I have modified the same script for groups instead of users as below, I am not getting any display
$adgroups = get-adgroup -searchbase "ou=test,dc=domain,dc=com" -filter * -Properties *
Foreach($adgroup in $adgroups)
{
if($adgroup.manager -ne $null)
{
$manager = Get-ADGroup -filter {Distinguishedname -eq $adgroup.manager}
if($($manager.enabled) -eq $false)
{
write-host "$($adgroup.SamAccountName),$($manager.SamAccountName)" -Path "C:\\Users\\test\\Desktop\\log.csv"
}
}
}
This should work.
$adusers = get-aduser -searchbase "ou=test,dc=domain,dc=com" -filter * -Properties manager
Foreach($aduser in $adusers)
{
if($aduser.manager -ne $null)
{
$manager = Get-ADUser -filter {Distinguishedname -eq $aduser.manager}
if($($manager.enabled) -eq $false)
{
Add-Content -Value "$($aduser.SamAccountName),$($manager.SamAccountName)" -Path "C:\Users\test\Desktop\log.csv"
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.