Powershell 缺少语句块
Powershell missing Statement block
我创建了一个脚本,用于将默认值应用到我的组织使用的 365 个租户。最后,我要求用户输入。我已经创建了一个 if else 语句,但它一直抱怨我没有 else 之后的语句块,我在这里做错了什么?
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization }
else ($SecureKeyWord -eq "N") {
Write-Host "No Secure KeyWord will be created"}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"
问题是 else
Else
不能包含一个语句吧。如果它不匹配 if
语句中的任何内容,它的默认值为 运行。 ElseIf
必须包含声明。
Else{}
ElseIf(Statement){}
这里是 else
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization
}else{
Write-Host "No Secure KeyWord will be created"
}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"
这里是 elseif
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization
}elseif($SecureKeyWord -eq "N"){
Write-Host "No Secure KeyWord will be created"
}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"
我创建了一个脚本,用于将默认值应用到我的组织使用的 365 个租户。最后,我要求用户输入。我已经创建了一个 if else 语句,但它一直抱怨我没有 else 之后的语句块,我在这里做错了什么?
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization }
else ($SecureKeyWord -eq "N") {
Write-Host "No Secure KeyWord will be created"}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"
问题是 else
Else
不能包含一个语句吧。如果它不匹配 if
语句中的任何内容,它的默认值为 运行。 ElseIf
必须包含声明。
Else{}
ElseIf(Statement){}
这里是 else
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization
}else{
Write-Host "No Secure KeyWord will be created"
}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"
这里是 elseif
$SecureKeyWord = Read-Host "Do you want to setup Secure Keyword Encryption (Y or N):"
If ($SecureKeyWord -eq "Y") {
$KeyWord = Read-Host "Enter KeyWord (secure or encrypt):"
New-TransportRule -Name "Secure KeyWord Encryption" -Enabled $True -SubjectContainsWords $Keyword -ApplyOME $true -ExceptIfSentToScope InOrganization
}elseif($SecureKeyWord -eq "N"){
Write-Host "No Secure KeyWord will be created"
}
Write-Host "All Defaults Have Been Set, Please Manually Set Password Policy and DLP Sensitive Data Types if Required"