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



0 Comments   [ + ] Show Comments


Please log in to comment



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.



'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
End If

'Get last 4 characters (numbers)
strName1 = Right(strComputer,4)


If you rather use Powershell then use:

$a = $a.substring(2,3)


Output CDE


Answered 10/02/2014 by: paul.theelen
Orange Senior Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja