I've pulled this together from some information online and added my own stuff to match my environment, but I'm getting a result that isn't quite what we need. Hoping someone can help!
The output is close, but I can't have a space after the last name:
What I'm getting:
Smith , Jim
Smith , Jane
What I need is:
Smith, Jim
Smith, Jane
Here's my script so far. Thank you in advance for any assistance!!! (the OU information has been changed for security reasons)
Import-Module ActiveDirectory
# All of the expressions you want with all of the filtering .etc you'd like done to them
$expressions=@(
# @{Expression={$_.surName},[char]8,",",{$_.givenName};Label="Name"},
@{Expression={$_.surName,",",$_.givenName};Label="Name"},
@{Expression={$_.emailAddress};Label="Email"}
)
$path_to_file = "C:\temp\Email_Address_Book$((Get-Date).ToString('yyyy-MM-dd_hh-mm-ss')).csv"
'OU=Users,OU=<site1>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM','OU=Users,OU=<site2>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site3>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site4>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM', 'OU=Users,OU=<site5>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site6>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' | ForEach-Object {
Get-ADUser -Filter 'enabled -eq $true' -SearchBase $_ -Properties *
} | Select $expressions | Export-Csv $path_to_file -NoTypeInformation -Encoding UTF8
Thanks again!!!
-Jeepix
The output is close, but I can't have a space after the last name:
What I'm getting:
Smith , Jim
Smith , Jane
What I need is:
Smith, Jim
Smith, Jane
Here's my script so far. Thank you in advance for any assistance!!! (the OU information has been changed for security reasons)
Import-Module ActiveDirectory
# All of the expressions you want with all of the filtering .etc you'd like done to them
$expressions=@(
# @{Expression={$_.surName},[char]8,",",{$_.givenName};Label="Name"},
@{Expression={$_.surName,",",$_.givenName};Label="Name"},
@{Expression={$_.emailAddress};Label="Email"}
)
$path_to_file = "C:\temp\Email_Address_Book$((Get-Date).ToString('yyyy-MM-dd_hh-mm-ss')).csv"
'OU=Users,OU=<site1>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM','OU=Users,OU=<site2>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site3>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site4>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM', 'OU=Users,OU=<site5>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' , 'OU=Users,OU=<site6>,OU=D Organization,DC=<domain>,DC=<domain>,DC=COM' | ForEach-Object {
Get-ADUser -Filter 'enabled -eq $true' -SearchBase $_ -Properties *
} | Select $expressions | Export-Csv $path_to_file -NoTypeInformation -Encoding UTF8
Thanks again!!!
-Jeepix