我创建了一个脚本,以将默认值应用于组织使用的365个租户。最后,我请用户输入。我创建了一个if 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"
答案 0 :(得分:1)
问题是else
Else
不能包含声明。如果它与if
语句中的任何内容都不匹配,它将运行的默认值。 ElseIf
必须包含一条语句。
Else{}
ElseIf(Statement){}
这里与其他人在一起
$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"