I need to compare enabled users in Active Directory with the user profile list from a server and then delete disabled profiles on the same server.
I'm trying to get a .csv list of users for each: one for the AD and one for the server.
When I get the server file, profiles are displayed like this: "domain\username" but with the AD file I only get: "username", so I can't compare them.
Ideally I would like to change the username when I get the AD file to add the domain. I tried to do something like this:
$Name = $_.SamAccountName
ForEach-Object {
Get-ADUser -Filter 'enabled -eq $true' | select-object SamAccountName
$Name = "DOMAIN\ + $Name"
}
$users | Export-Csv c:\USEREnabled.csv -Encoding UTF8
Which returns the .csv file with all SamAccountName but without any change done.