I have a simple script and I'm trying export csv file with only two columns $findUser.Name and $userStatus but I'm not sure why it's not exporting the value for those two.
Any help or suggestion would be really appreciated.
$groupdMember = Get-AdGroupMember -Identity $GroupName
foreach($member in $groupdMember){
$findUser = Get-ADUser -Identity $member.Name
if($findUser.Enabled -eq "False"){
$userStatus = "Disabled"
}else{
$userStatus = "Enabled"
}
Write-Host $findUser.Name, $userStatus
$member | Select-Object $findUser.Name, $userStatus | Export-Csv -Path E:\scripts\aduser-report.csv -Append -notypeinformation -force
}
If I removed the Select-Object then it able to export it but it's not what I wanted. I just wanted to export a csv file that have only $finduser.Name and $userStatus.
... | Select-Object @( "Name", "Enabled" ) | ..., or more simply... | Select-Object Name, Enabled | .... The parameters need to be the names of the properties, not the their values - at the moment you're telling it to select the properties called literally "My User XYZ" (or whatever the user's name is) and "Disabled" or "Enabled" (which will work when the user is enabled because the property is called "Enabled", but it won't work when the user is "Disabled")ObjectClass?