Hi All,
I am using the following script to check recipients and types and add aliases from the feed file.
#Get the name of the file that will be added to Domain Reports Folder
$filename = Read-Host "Enter the domain name"
# Filepath of the feed file for specific domain
$filepath = Read-Host "Enter the feed file path"
$filepath = $filepath.Replace('"','') # Removes quotes when pasting the path
# Import CSV and process each object
import-Csv $filepath | ForEach-Object {
$recipient = Get-Recipient $_.Email
$output = New-Object PSObject -Property @{
Alias = $_.Alias
Email = $_.Email
PrimarySmtpAddress = $recipient.PrimarySmtpAddress
RecipientTypeDetails = $recipient.RecipientTypeDetails
}
$output
# Depending on the RecipientTypeDetails, perform the appropriate action
if ($_.RecipientTypeDetails -eq "MailUniversalDistributionGroup") {
Set-DistributionGroup $_.Email -EmailAddresses @{add=$_.Alias}
}
else {
Set-RemoteMailbox $_.Email -EmailAddresses @{add=$_.Alias}
}
} 2>> "C:\Users\Documents\Projects\Domain Map Decom\Domain Reports\$filename`_AliasErrors.txt" | Export-Csv "C:\Users\Documents\Projects\Domain Map Decom\Domain Reports\$filename`_AliasChecked.csv" -NTI 2>> "C:\Users\Documents\Projects\Domain Map Decom\Domain Reports\AliasAddErrors.txt"
I’m having a hard time understanding why the if condition is ignored and goes straight to the else condition. Any guidance is appreciated.
Thanks in advance!