Good day,
This is my very first post on the forums :) I ran into the site when looking to figure out what I am doing wrong with my script. I hope someone can maybe point me in the right direction.
I have a list of users (about 500) who need an email alias added to their mailboxes (Exchange 2010) and so I figured I would create a script to do so. The script imports the usernames from a CSV file and using a variable I concatenate what the new email address will look like. From there I use a simple For loop to run the command for each element of the array containing the imported data from the CSV. The script looks as follows:
------------------------------
$UsrName = @()
$CSVPath = "C:\PowerShell\UsrEmail.csv";
$UsrName = Get-Content -path $CSVPath;
For ($i=0; $i -lt $UsrName.length; $i++)
{
$usridemail = $UsrName[$i] + "@company.com";
$usridemail;
Set-RemoteMailbox $UsrName[$i] -EmailAddresses @{Add="$useridemail"};
}
------------------------------
Using the double quotes in the command, I expected it to evaluate the $useridemail variable and poof, I would be good to go. However it doesn't appear to be the case.. I get the following error:
user@company.com
Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "System.Collections.Hashtable" to type "Microsoft.Exchange.Data.ProxyAddressCollection". Error: "Failed to convert from System.String to Microsoft.Exchange.Data.ProxyAddress. Error: Error while converting string '' to result type Microsoft.Exchange.Data.ProxyAddress: The e-mail address cannot be empty." + CategoryInfo : InvalidData: (:) [Set-RemoteMailbox], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-RemoteMailbox
So with my limited understanding of powershell... from what I can see is that it is not evaluating the $useridemail variable when attempting to add the new email address to the mailbox.
I also have to apologize as I am sure there is a much more efficient way to write a script that does this, but my knowledge of powershell is fairly limited. Any help would be very appreciated.
If I run the set-remotemailbox command manually, and input the username and desired email address it works fine. So there is something about that variable it doesn't like.