变量引用无效
Variable reference is invalid
任何人都可以帮我解决这个问题,我还没有找到与此相关的任何内容。
这是我的脚本:
#Connect to Exchange PowerShell Online
Connect-ExchangeOnline -UserPrincipalName username@domain.com
$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
错误信息是我自己粗略翻译的,所以可能不准确。
“变量引用无效。”:“后面没有跟一个有效的变量名称字符”
PowerShell 变量表达式可以包含 :
以分隔作用域修饰符或路径根,因此当您执行 $userprincipalName:\Calendar
.
时,PowerShell 会尝试将其作为变量名称的一部分包含在内
为防止出现这种情况,请使用 {}
限定变量名称的边界,PowerShell 会将字符串参数的其余部分解释为字符串文字,例如:
Set-MailboxFolderPermission ${userPrincipalName}:\Calendar -user Default -accessrights LimitedDetails
对 ${userPrincipalName}:\Calendar
的所有实例重复,错误将消失。
任何人都可以帮我解决这个问题,我还没有找到与此相关的任何内容。
这是我的脚本:
#Connect to Exchange PowerShell Online
Connect-ExchangeOnline -UserPrincipalName username@domain.com
$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
错误信息是我自己粗略翻译的,所以可能不准确。
“变量引用无效。”:“后面没有跟一个有效的变量名称字符”
PowerShell 变量表达式可以包含 :
以分隔作用域修饰符或路径根,因此当您执行 $userprincipalName:\Calendar
.
为防止出现这种情况,请使用 {}
限定变量名称的边界,PowerShell 会将字符串参数的其余部分解释为字符串文字,例如:
Set-MailboxFolderPermission ${userPrincipalName}:\Calendar -user Default -accessrights LimitedDetails
对 ${userPrincipalName}:\Calendar
的所有实例重复,错误将消失。