Today I was handed a CSV list of AD users and asked to return the list with an “Enabled” column to represent wether a user was enabled or disabled in Active Directory. I used PowerShell to quickly whip this up. For future reference, here is the PowerShell that will take a CSV with a “User” column (that contains the user account name) and generates another CSV with the AD properties desired (in this case enabled, sam account name, and email address).
Import-CSV -Path .\mailbox_access_list.csv | ForEach-Object { Get-ADUser ($_.User) -Properties Enabled,EmailAddress,SamAccountName | select Enabled,EmailAddress,SamAccountName } | Export-CSV .\results.csv -NoTypeInformation ### - Pablo Aizpiri
Also, for those times when you quickly need to get users in a AD group using PowerShell…
Get-ADGroupMember [AD Group Name] | select {"[Domain Name]\" + $_.samAccountName} ### - Pablo Aizpiri
Getting emails from a group:
Get-ADGroupMember [AD Group Name] | ForEach-Object { Get-ADUser ($_.samAccountName) -Properties EmailAddress | select EmailAddress } ### - Pablo Aizpiri
Leave a Reply