Troubleshooter5000 Posted December 21, 2020 Posted December 21, 2020 (edited) 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? Edited December 21, 2020 by Troubleshooter5000
Developers Jos Posted December 21, 2020 Developers Posted December 21, 2020 StringLeft()? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Musashi Posted December 22, 2020 Posted December 22, 2020 8 hours ago, Troubleshooter5000 said: How can I write a script that looks for only the first 2 characters of the computer name? Switch StringLeft(@ComputerName, 2) Case "AB" ; RunWait(Thing1) Case "CD" ; RunWait(Thing2) Case "EF" ; RunWait(Thing3) Case Else ConsoleWrite('! >>> Computername not found' & @CRLF) EndSwitch "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now