Hi Guys!
I might think some of you are able to help me out with this little problem I have when I try using PowerShell and PSSnapin for Exchange 2010.
The problem I have occur when I want to change a users' EmailAddress from
firstname.lastname@domain.com to something like disabled.firstname.lastname@domain.com.
If I type it manually, like "Set-Mailbox -Identity User01 -Emailadresses 'SMTP:disabled.firstname.lastname@domain.com'" it works perfectly fine. The problem occurs when I want to get this to work in a script aswell.
Because then I want the script to automatically save the users EmailAddress into a variable for reuse later in the script.
So what I've done so far is:
$Var = Get-Mailbox -Identity User01 | Select-Object PrimarySMTPAddress Set-Mailbox -Identity User01 -EmailAddresses "disabled.$Var"
But when I try that I get the error message from PowerShell saying:
"Cannot convert value "disabled.@{PrimarySMTPAddress=firstname.lastname@domain.com}" to type "Microsoft.Exchange.ProxyAddressCollection". Error: "The address 'disabled.@{PriamrySMTPAddress=firstname.lastname@domain.com}' is
invalid.
I understand why it's not possible to set an EmailAddress like "disabled.@{PriamrySMTPAddress=firstname.lastname@domain.com".
The question is if there are any other ways to retrive only firstname.lastname@domain.com and put that information into a variable for proper reuse.
Thanks!