Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - detecting odd/even computername

$
0
0

Hi All,

I have the following code as part of a larger script;

$OddEvenCheck = $ENV:COMPUTERNAME.Substring($ENV:COMPUTERNAME.Length - 1)
$OddEvenCheck = if ($OddEvenCheck % 2 -eq 0 ) {"even"}
Elseif ($OddEvenCheck % 2 -eq 1 ) {"odd"}

The script, in its whole form, is designed to have a list of gateways as variables. It then runs as a startup script and detect the gateway and hostname of the local computer.

If the computers hostname ends with an odd numeric value and belongs to gateways from site 1 variable then it adds network printer connections from the print server 1.

If the computer hostname ends with an even numeric value and belongs to gateways from site 1 variable then it adds network printer connections from the print server 2.

etc etc.

What I can't quite figure out is how to trap the scenario whereby a computers hostnamedoesn't end with a numeric. Any advice would be greatly appreciated!

Adam


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

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