/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


How to pull numbers from a string and replace the target with those numbers?

10/01/2014 1816 views

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

Comments


All Answers

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

 

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

 
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