Avatar of Brian
Brian
Flag for United States of America

asked on 

How do I run a command line if statement in a PowerShell script

I have the following PowerShell command that is working...
& "C:\Program Files\MyProgram\MyCMDprogram.exe" -Enable 7584345

Open in new window

But I want to test for the computer name.  If I add an if statement like this...
& if %computername%==xyz123 "C:\Program Files\MyProgram\MyCMDprogram.exe" -Enable 75843456

Open in new window

It fails saying that "The term 'if' is not recognized..."
How can I run this command in PowerShell?  In a batch file, it would look like this...
if %computername%==xyz123 "C:\Program Files\MyProgram\MyCMDprogram.exe" -Enable 75843456

Open in new window

Powershell

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon