Serverlokale Gruppen importieren



Mindestanforderung von migRaven ist die Version 1849

Anpassung der c:\program files\migraven\migraven.exe.config

Ohne Ausschluss

<add key=“Flatten“ value=“y.type=’person‘ and y.isactive=’True‘ “ />

Exportieren der CSV-Dateien für die Serverlokalen Gruppen:

 


$Computer = "SERVER"
$gruppen = get-wmiobject win32_group -filter "LocalAccount='True'" -ComputerName $Computer
foreach($groupName in $gruppen){
$Gname = $groupName.Name
#$Gname
$Group= [ADSI]"WinNT://$Computer/$Gname,group"
#$Group
$members = $Group.psbase.Invoke("Members")
$name = $members | ForEach-Object { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }
if($groupName.Description -eq "" )
{$groupName.Description = "leer" }
 
[System.Guid]::NewGuid().ToString() + "t" + $groupName.SID + "t" + $groupName.Name +  "t" + $Computer + "t" + $groupName.Description  | out-file  -filePath "c:\temp\lokaleGruppen.csv" -Append
#$name
#$members
foreach ($n in $name){
if (  $n.ToString() -notcontains "System." ) {
      write-host $n
        $memb = (New-Object System.Security.Principal.NTAccount($n)).Translate([System.Security.Principal.SecurityIdentifier]).value
        $groupName.SID + "," + $memb | out-file  -filePath "c:\temp\MemberGruppen.csv" -Append
      }
 
}
}

Entfernen der verwaisten ACEs vor dem ausführen der abschliessenden Scripts mit

MATCH (n:ACE) where not (n)-[:rel_ace]->() detach delete n

Gruppen miteinander verbinden

 
profile LOAD CSV FROM 'file:///C:/temp/lokaleGruppen.csv' AS line FIELDTERMINATOR '\t' with line,
'merge (l:ADAccount {objectGUID:"' +  line[0] + '" }) on create set l.objectSID="' + line[1] +'" set l.name="'+ line[2]
+ '" set l.domain="' + line[3] + '" set l.commonsid="0" set l.type="group" set l.sAMAccountName="' + line[2] + '" set l.cn="'+ line[2]
+'" set l.distinguishedname="" set l.isactive="True" set l.department="" set l.description="'+ line[4] + '" set l.displayname="" set l.givenName=""
set l.grouptype="" set l.sn="" set l.sAMAccountType="SAM_NON_SECURITY_GROUP_OBJECT" set l.ad="1" set l.grouptype="Universal_Security_Group"
set l.adspath="LDAP://' + line[3] + '/CN=' + line[2]  + ',CN=Users,DC=' + line[3] + '"'  as cypher  CALL apoc.cypher.doIt(cypher,{}) yield value
return value





profile USING PERIODIC COMMIT 1000 LOAD CSV FROM 'file:///c:/temp/MemberGruppen.csv' AS line FIELDTERMINATOR ',' match (l:ADAccount {objectSID: line[0]}) match (d:ADAccount {objectSID:line[1]}) merge (l)-[:rel_member]->(d)
 


LOAD CSV FROM 'file:///C:/temp/lokaleGruppen.csv' AS line FIELDTERMINATOR '\t' merge (l:ADAccount {objectGUID: line[0] }) on create set l.objectSID= line[1], l.name=line[2], l.domain=line[3], l.commonsid='0', l.type='group', l.sAMAccountName= line[2], l.cn= line[2] , l.distinguishedname='cn=' + line[2] + ',dc=' + line[3], l.isactive='', l.department='', l.description= line[4], l.displayname='', l.givenName='', l.grouptype='', l.sn='', l.sAMAccountType='SAM_NON_SECURITY_GROUP_OBJECT', l.ad='1', l.grouptype='Universal_Security_Group', l.adspath=''
 
USING PERIODIC COMMIT 1000 LOAD CSV FROM 'file:///c:/temp/MemberGruppen.csv' AS line FIELDTERMINATOR ',' match (l:ADAccount {objectSID: line[0]}) match (d:ADAccount {objectSID:line[1]}) merge (l)-[:rel_member]->(d)



Permanentlink zu diesem Beitrag: https://help.migraven.com/neo4j-serverlokale-gruppen-importieren/