I have been working on a creating a script to replace the following commandlet. The following commandlet works just fine but I need to manually replace the domain information and thought a script would help simplify the process.
Get-recipient -ResultSize unlimited -Filter {emailaddresses -Like "*@domain.com"} | Select DisplayName,Name,City,PrimarySMTPAddress,RecipientTypeDetails,OrganizationalUnit, @{Name="Emailaddresses";expression={$_.Emailaddresses | where {$_ -like "*smtp:*@domain.com*"}}} | export-csv "C:\temp\domain.csv" -NoTypeInformation
The following is the script I’ve created but the output does not output any content or values in the emailaddresses column.
$Domain = $Null
$Domainwild = $Null
$Domaincsv = $Null
$Domain = Read-Host "Enter the name of the domain Ex: publicisresources.com"
$Domainwild = "*" + $Domain
$Domaincsv = $domain + ".csv"
Get-recipient -ResultSize unlimited -Filter "emailaddresses -Like '$Domainwild'" |
Select-Object DisplayName, Alias, PrimarySMTPAddress, RecipientTypeDetails,
@{
Name = "EmailAddresses"; Expression = {
($_.EmailAddresses |
Where-Object { $_ -like "smtp:*$domain" } | ForEach-Object { $_ -replace "smtp:", "" }) -join ","
}
} |
export-csv "C:\temp\$Domaincsv" -NoTypeInformation
Anyone see what I’m missing or doing wrong here?