所以我得到了这个脚本,它应该更改office365中的类别颜色,来自powershell .............................. ...................................
脚本:
$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")
}
错误代码:
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
我的Csv文件:
"MessageId","MailboxName"
"<HE1P192MB018554247E4F4A81D830F19DD1820@HE1P192MB0185.EURP192.PROD.OUTLOOK.COM>","email@domaion.com"
所以我的问题是。是我的代码中有错误,还是在Exch-Rest工具中?
希望有人知道如何解决这个问题。
度过美好的一天!
答案 0 :(得分:0)
“我的代码是否存在错误,或者它是否在Exch-Rest工具中?” 是你。这几乎总是你。这是为什么外部库中的错误很难找到的原因的一半:)
您在哪里初始化$ Mailbox变量? 如果它来自您的CSV文件,那么您应该使用
private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}