Hello,
how can I force the "" around the parameter with an & in
All you need to do is to specify the variable value in double quotes. For example, if you specify the value explicitly, it should look like this:
$name = "John & Doe"
$address = "j&d@domain.com"
New-MailUser -Name $name -ExternalEmailAddress $address
how to I get detailed error messages of why the command failed so I can troubleshoot it better.
To catch the exception returned by a cmdlet, use a try/catch block. Also, you need to specify the Stop value in the ErrorAction parameter of the cmdlet. The whole approach should look like this:
try
{
New-MailUser -Name $name -ExternalEmailAddress $address -ErrorAction Stop
}
catch
{
$Context.LogMessage("The following error occurred: " + $_Exception.Message, "Warning")
}