Moin nochmal.
Die mit --------------> markierten Aufrufe (MIT Variablen) gegen kein Ergebnis zurück. Direkt daruter (aktuell auskommentiert) steht genau der selbe Aufruf OHNE Variablen im Aufruf. Jener funktioniert. Was mache ich falsch?
remove-item c:\skripte\result.txt
wait-event -timeout 3
$oulist = @(Get-ADOrganizationalUnit -SearchScope 1 -Searchbase "OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" -Filter 'Name -like "*"' | foreach {$_.Name})
#$oulist
foreach ($ou in $oulist)
{
"#######################$ou#######################" | out-file c:\skripte\result.txt -Append
Get-ADUser -filter {(description -notlike "*") -and (userAccountControl -eq 512)} -SearchBase "OU=$ou,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.SamAccountName} | out-file c:\skripte\results.txt -Append
$anzahl = (Get-ADUser -filter {(description -notlike "*") -and (userAccountControl -eq 512)} -SearchBase "OU=$ou,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.SamAccountName}).count
-------------->$officegroups = @(Get-ADGroup -filter {(name -like "*MSOffice*")} -SearchBase "OU=$ou,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.name})
#$officegroups = @(Get-ADGroup -filter {(name -like "*MSOffice*")} -SearchBase "OU=ou4,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.name})
$office = $null
$officegesamt= $null
foreach ($officegroup in $officegroups)
{
-------------->$office = (Get-ADUser -filter {(description -notlike "*") -and (userAccountControl -eq 512) -and (memberof -recursivematch "CN=$officegroup,OU=$ou,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local")} -SearchBase "OU=$ou,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.SamAccountName}).count
#$office = (Get-ADUser -filter {(description -notlike "*") -and (userAccountControl -eq 512) -and (memberof -recursivematch "CN=cn1,OU=ou4,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local")} -SearchBase "OU=ou4,OU=ou3,OU=ou2,OU=ou1,DC=domain,DC=local" | foreach {$_.SamAccountName}).count
$officegesamt = $officegesamt + $office
}
"Anzahl: $anzahl" | out-file c:\skripte\result.txt -Append
"Anzahl MS Office: $officegesamt" | out-file c:\skripte\result.txt -Append
}