Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

String comparison and switch

$
0
0

I have a portion of a script that isn't working like it should. It works on my machine (v5), another test machine(v5), but not on another machine (v4). Essentially I am detecting the model of the machine, and depending on the model, I will start a program. Not much to my code, but here it is:

Powershell
$System=(Get-WmiObjectwin32_computersystem)switch($System.Model){"XPS 15 9550"{Start-Process'\\files\program.exe'-Wait}"Optiplex 760"{Start-Process'\\files\program.exe'-Wait}"Optiplex 780"{Start-Process'\\files\program.exe'-Wait}#More models below}

The problem I am having is with the string comparison portion on the v4 machine (an Optiplex 760) so the switch statement never triggers. When I pipe $System.Model to Get-Member, it shows the type as a string. But, when I compare it by doing:

Powershell
$System.Model-eq...

Viewing all articles
Browse latest Browse all 15370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>