/build/static/layout/Breadcrumb_cap_w.png

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

 


 


0 Comments   [ + ] Show comments

Answers (1)

Posted by: paul.theelen 9 years ago
Orange Senior Belt
0

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

 

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ