我正在尝试使用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()
}
}
ERROR:
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
答案 0 :(得分:1)
检查邮箱是否存在以及别名是否正确。