troubleshooting Question

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

Avatar of Brian
BrianFlag for United States of America asked on
Powershell
2 Comments1 Solution13 ViewsLast Modified:
I have the following PowerShell command that is working...
& "C:\Program Files\MyProgram\MyCMDprogram.exe" -Enable 7584345
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
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros