I am trying to pull some information for an O365 migration.
This command works fine:
get-mailbox -Filter {windowsemailaddress -eq "saorders@domain.com"} | fl windowsemailaddress, primarysmtpaddress
and returns the expected result. I am going to use a CSV to make a variable for several email addresses. For right now I hard coded a variable for simplicity:
$UPN = "saorders@domain.com"
If I plug that in:
get-mailbox -Filter {windowsemailaddress -eq "$UPN"} | fl windowsemailaddress, primarysmtpaddress
I get the following error:
Invoke-Command : Cannot bind parameter 'Filter' to the target. Exception setting "Filter": "The value "$upn" could not
be converted to type Microsoft.Exchange.Data.SmtpAddress."
At C:\Users\a_mscott\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\usp306.domain.com\usp306.domain.com.psm1:13613 char:
29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : WriteError: (:) [Get-Mailbox], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
What syntax do I need to use in this case to use a variable there?