Tekwhat
Tekwhat

Reputation: 37

Powershell missing Statement block

I have created a script to apply defaults to 365 tenants that my organization uses. At the end, I ask the user for input. I have created a if else statement, but it keeps complaining that I do not have a statement block after else, what am I doing wrong here?

$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"

Upvotes: 1

Views: 4581

Answers (1)

ArcSet
ArcSet

Reputation: 6860

The issue is the else

Else can not contain a statement it. Its the default value of what will run if it doesn't match anything in the if statement. ElseIf must contain a statement.

Else{}

ElseIf(Statement){}

Here is with 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"

and here is with 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"

Upvotes: 1

Related Questions