How to pull numbers from a string and replace the target with those numbers?
I am fairly new to scripting so this might be easy for most but I am trying to pull the first two numbers from the computer name and replace the XX in this file address with them. The sytems the script I am writing to be deployed to will have different file shares holding the software.
computer name will look like this ow44p44pos
COPY \\srvXX\dsXX\pos\pinpad\usb_installvfi_3_1.msi c:\pcms\install TIMEOUT 5
the end result should be the 44 from the computer name replacing the XX in \\srvXX\dsXX\pos\pinpad\usb_installvfi_3_1.msi
Answers (1)
I created a VBScript in 2012 which should help you achieve what you need.
This is a small part of it.
You will probably need to use the function called mid instead of right.
http://www.w3schools.com/vbscript/func_mid.asp
'Created by Paul Theelen at 09-08-2012
'Declare variables
Dim strName1
Dim strComputer
'Get computername
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'Check if computername is 12 characters long in case a typo was made in the computername.
If Len(strComputer) <> 12 Then
wScript.Quit
End If
'Get last 4 characters (numbers)
strName1 = Right(strComputer,4)
If you rather use Powershell then use:
$a="ABCDEFG"
$a = $a.substring(2,3)
Output CDE
http://technet.microsoft.com/en-us/library/ee176901.aspx