Link to home
Start Free TrialLog in
Avatar of Brian
BrianFlag 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

Avatar of Shabarinath TR
Shabarinath TR
Flag of India image

IF([System.Net.Dns]::GetHostName() -match "YourComputerName"){"C:\Program Files\MyProgram\MyCMDprogram.exe" -Enable 75843456 }

Cheers !
Shaba
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial