誰能幫我解決這個問題,我找不到與此相關的任何內容。
這是我的腳本:
#Connect to Exchange PowerShell Online
Connect-ExchangeOnline -UserPrincipalName [email protected]
$repeatX = Read-Host -Prompt 'How many email to update?'
Write-Host "Configuring default calendar permissions..."
for($i = 1; $i -le $repeatX; $i ) {
$userPrincipalName = Read-Host -Prompt 'Enter email address'
do {
$type=Read-Host ""`n============= What is the country?=============="
1 - France
2 - United States
3 - Hong Kong SAR
4 - United Kingdom
Please choose with numbers"
Write-Host "==================================================="
Switch ($type){
1 {$country="France"}
2 {$country="United States"}
3 {$country="Hong Kong SAR"}
4 {$country="United Kingdom"}
}
} until (($country -eq 'France') -or ($country -eq 'United States') -or ($country -eq 'Hong Kong SAR') -or ($country -eq 'United Kingdom'))
$country
if ($country -eq 'United States') -or ($country -eq 'Hong Kong SAR') -or ($country -eq 'United Kingdom') {
Set-MailboxFolderPermission $userPrincipalName:\Calendar -user Default -accessrights LimitedDetails
Set-CalendarProcessing -Identity $userPrincipalName -AddOrganizerToSubject $true -DeleteComments $false -DeleteSubject $false
}
elseif($country -eq 'France') {
Set-MailboxFolderPermission $userPrincipalName:\Calendrier -user Default -accessrights LimitedDetails
Set-CalendarProcessing -Identity $userPrincipalName -AddOrganizerToSubject $true -DeleteComments $false -DeleteSubject $false
}
}
這是有問題的代碼部分: https ://i.stack.imgur.com/WU4z0.png
并且錯誤資訊是我自己粗略翻譯的,所以可能不準確。
“變數參考無效。“:”后面沒有有效的變數名稱字符“
uj5u.com熱心網友回復:
PowerShell 變數運算式可以包含:以分隔作用域修飾符或路徑根,因此當您執行$userprincipalName:\Calendar.
為防止這種情況發生,請使用{}來限定變數名稱的邊界,PowerShell 會將字串引數的其余部分解釋為字串文字,例如:
Set-MailboxFolderPermission ${userPrincipalName}:\Calendar -user Default -accessrights LimitedDetails
重復所有的實體,${userPrincipalName}:\Calendar錯誤就會消失。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/454874.html
