0

I have a batch script. I want to change it to powershell script. Is my code below the same purpose?

My batch script

IF %ODM% EQU 1 (
    ECHO #ODM# detected
    IF %Stage% EQU 10 (
        ECHO  Stage Code 10
    )
)

Powershell script

If ($ODM = "1")
{Write-Host "#ODM# detected"}
if ($Stge = "10")
{Write-Host "Stage Code 10"}
2
  • 3
    The equals comparison operator in PowerShell is -eq and not the assignment operator =. Commented Jun 12, 2019 at 13:24
  • 1
    are %ODM% and %Stage% environment-variables ? if so, you'll need to change $ODM to $env:ODM Commented Jun 12, 2019 at 13:31

1 Answer 1

3

Not exactly, it looks like the batch code you supplied had nested if statements whereas you PowerShell code just had two seperate if statements.

So you would be looking at something like this:

if ($ODM -eq "1"){
    Write-Host "$ODM detected"
    if ($Stge -eq "10"){
        Write-Host "Stage code 10"
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.