I want to run an if statement based on the first 2 characters of the computer name and nothing else. The kicker is that the first 2 characters could exist elsewhere in the computer name. That presents a problem when I want to generalize this script and not worry about the entire computer name. For example, I want my if statement to function something like this.
If computer name starts with “AB”, then do Thing1.
ElseIf computer name starts with “CD”, then do Thing2.
ElseIf computer name starts with “EF”, then do Thing3.
EndIf.
I already have a script to perform this task but it only looks for if the string contains the characters, not starts with. Here’s the actual code:
If StringInStr ( @computername , "AB" ) Then
RunWait ( Thing1 )
ElseIf StringInStr ( @computername , "CD" ) Then
RunWait ( Thing2 )
ElseIf StringInStr ( @computername , "EF" ) Then
RunWait ( Thing3 )
EndIf
This presents a problem when the list of computers I run this on looks like this:
ABAB1234
CDAB1234
EFCD1234
How can I write a script that looks for only the first 2 characters of the computer name? Should I just break down and use AutoIt to run a batch file instead?