I'm assigning the Get-Mailbox command to a variable so that I can output this to a log file:
$SmtpForwardingAddress = Get-Mailbox -Identity $Upn | Select ForwardingSmtpAddress
"Email forwarding set to $($SmtpForwardingAddress)" | Tee-Object $logfilepath -Append
The variable $SmtpForwardingAddress returns:
"Email forwarding set to @{ForwardingSmtpAddress=smtp:[email protected]}"
I'd like to trim this to just the [email protected] value. I've tried a couple of things but get errors like the below:
Method invocation failed because [Selected.System.Management.Automation.PSCustomObject] does not contain a method named 'substring'.
Method invocation failed because [Selected.System.Management.Automation.PSCustomObject] does not contain a method named 'Trim'.
Any ideas as to what I can do to get the desired result?
$SmtpForwardingAddress?