So i got this script, it should change the category color in office365, from powershell.................................................................
Script:
$messages = Import-Csv -Path c:\temp\messageid.csv
Connect-EXRMailbox -Mailbox "email@domain.com"
ForEach ($message in $messages){
$MessageId = $message.MessageId
$MailboxName = $message.MailboxName
$Item = Find-EXRMessageFromMessageId -MailboxName $MailboxName -MessageId $MessageId
Set-EXRItemCategory MailboxName $MailboxName -Item $Item -Categories @("Green")
}
Error code:
New-Object : Exception calling ".ctor" with "1" argument(s): "The specified string is not in the form required for an e-mail address."
At line:17 char:19
+ ... stDomain = (New-Object system.net.Mail.MailAddress($MailboxName)).Hos ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At line:18 char:8
+ if ($Script:TokenCache.ContainsKey($HostDomain))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
New-Object : Exception calling ".ctor" with "1" argument(s): "The specified string is not in the form required for an e-mail address."
At line:17 char:19
+ ... stDomain = (New-Object system.net.Mail.MailAddress($MailboxName)).Hos ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At line:18 char:8
+ if ($Script:TokenCache.ContainsKey($HostDomain))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Get-EXRAccessToken : No Access Token for MailboxName
At line:31 char:32
+ ... $AccessToken = Get-EXRAccessToken -MailboxName $MailboxName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-EXRAccessToken
Get-EndPoint : Cannot bind argument to parameter 'AccessToken' because it is null.
At line:38 char:47
+ $EndPoint = Get-EndPoint -AccessToken $AccessToken -Segment " ...
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-EndPoint], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-EndPoint
New-Object : Exception calling ".ctor" with "1" argument(s): "The specified string is not in the form required for an e-mail address."
At line:17 char:19
+ ... stDomain = (New-Object system.net.Mail.MailAddress($MailboxName)).Hos ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At line:18 char:8
+ if ($Script:TokenCache.ContainsKey($HostDomain))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
New-Object : Exception calling ".ctor" with "1" argument(s): "The specified string is not in the form required for an e-mail address."
At line:17 char:19
+ ... stDomain = (New-Object system.net.Mail.MailAddress($MailboxName)).Hos ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At line:18 char:8
+ if ($Script:TokenCache.ContainsKey($HostDomain))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Get-EXRAccessToken : No Access Token for MailboxName
At line:24 char:20
+ ... $AccessToken = Get-EXRAccessToken -MailboxName $MailboxName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-EXRAccessToken
Invoke-RestPatch : Cannot bind argument to parameter 'AccessToken' because it is null.
At line:32 char:92
+ ... $RequestURL -HttpClient $HttpClient -AccessToken $AccessToken -Mailbo ...
+ ~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-RestPatch], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Invoke-RestPatch
My Csv file:
"MessageId","MailboxName"
"<HE1P192MB018554247E4F4A81D830F19DD1820@HE1P192MB0185.EURP192.PROD.OUTLOOK.COM>","email@domaion.com"
So my question is. Is it my code there is an error in, or is it in the Exch-Rest tool ?
Hope anyone knows how to fix this .
Have a really nice day!
"Is it my code there is an error in, or is it in the Exch-Rest tool ?" It's you. It's almost always you. That's half of why bugs in external libraries are so hard to find :)
Where do you initialise your $Mailbox variable? If it's from your CSV file, then you should use
$message.MailboxName
$message.MessageID
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.