powershell を使用して Exchange 2010 で予定をカレンダーに入力しようとしています。しかし、保存する最後の行でエラーが発生します。SMTP には関連付けられたメールボックスがありません。これを行うために管理者ユーザーを使用しているため、なぜ機能しないのかわかりません。以下はコードです
Param ([string]$calInputFile = $(throw "Please provide calendar input file..."))
# Testing
#$calinputfile="d:\calendar_inject.csv"
# Connect to Live@edu
# capture the admin LiveID username in a variable
$Username = "administrator@domainasa.com"
# capture the admin LiveID password in a variable. Note, that it is stored as a secure string
$Password = ConvertTo-SecureString ‘password’ -AsPlainText -Force
# populate the $Livecred PowerShell credential with $Username and $Password
$Livecred = New-Object System.Management.Automation.PSCredential $Username, $Password
#$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://thor.uk.domainasa.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
#Import-PSSession $Session
# Load EWS Managed API library
Import-Module -Name "C:\Program Files\Symantec\Backup Exec\Microsoft.Exchange.WebServices.dll"
# Load all Mailboxes
#$exchangeUsers = Get-Mailbox -ResultSize Unlimited | Select UserPrincipalName
#test with just one user
$exchangeusers = get-mailbox "sharif uddin" |select UserPrincipalName
# Load all calendar Entries
$calEntries = Import-Csv $calInputFile
# Identify the folder to save our appointments into
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar)
# Create Exchange Service object
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.Exchangeversion]::exchange2010)
$service.Url = new-object System.Uri("https://thor.uk.domainasa.com/EWS/Exchange.asmx")
# Service account must have ApplicationImpersonation ManagementRoleAssignment in Exchange
$service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("administrator@domainasa.com","woki1141")
foreach($mailbox in $exchangeUsers)
{
# Identify user to which appointment will be added
$MailboxName = $mailbox.UserPrincipalName
# Instruct service to use impersonation
$iUserID = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$MailboxName)
#Write-Output $iUserID
$service.ImpersonatedUserId = $iUserID
Write-Output $service
# Create new appointment object for each appointment to save
foreach($entry in $calEntries)
{
$appt = New-Object Microsoft.Exchange.WebServices.Data.Appointment($service)
$appt.Subject = $entry.Subject
# Convert date
$x = Get-Date -Date $entry."Start Date"
$y = Get-Date -Date $entry."End Date"
$appt.Start = [System.DateTime]( $x )
$appt.End = [System.DateTime]($y) #For AllDayEvent, end date must be after start date
$appt.IsAllDayEvent = $True
$appt.LegacyFreeBusyStatus = "Free"
$appt.IsReminderSet = $False #If you want a reminder then remove this line
#$appt.Save($folderid)
$appt.Save()
}
}
エラー:
Exception calling "Save" with "0" argument(s): "The SMTP address has no mailbox associated with it."
At C:\exchange.ps1:55 char:14
+ $appt.Save <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException