Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace string 1

Status
Not open for further replies.

GrimR

IS-IT--Management
Jun 17, 2007
1,149
ZA
Please help with replace string
When I get the Dell model number it comes out as Latitude E5430 non-vPro
I would like to strip out the words Latitude & non-vPro

NOTE: E5430 may be any Dell Model not specifically that one.
Was thinking of something like below but not working

If it could be done with an array or dictionary so I could add other words to it if need be.
Thanks

Code:
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 

For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem")
	
  model = trim(replace(objComputer.Model, ",", "."))

  if InStr(objComputer.Model,"Latitude" & "non-vPro") then
    model = TRIM(replace(objComputer.Model,InStr(objComputer.Model,"Latitude" & "non-vPro")))
end if

Next

wscript.echo model

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Something like this for a start:

Code:
arrToReplace = Array("Latitude","non-vPro")

For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem")
   model = trim(replace(objComputer.Model, ",", "."))

   For Each sToReplace in arrToReplace
      model = Trim(Replace(model, sToReplace, ""))
   next

Next
 
Seems to be working perfectly [may look a bit ugly for the programmers out there


Code:
On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 

For Each objSMBIOS in objWMI.ExecQuery("Select * from Win32_SystemEnclosure") 
  serviceTag = replace(objSMBIOS.SerialNumber, ",", ".")
  manufacturer = replace(objSMBIOS.Manufacturer, ",", ".")
Next

arrToReplace = Array("Latitude","non-vPro")

For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem")
   model = trim(replace(objComputer.Model, ",", "."))

   For Each sToReplace in arrToReplace
      model = Trim(Replace(model, sToReplace, ""))
   next
Next 

Set objSysInfo = CreateObject("ADSystemInfo") 
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
'Grab the user name
UserString = WshNetwork.UserName
Set objADSysInfo = CreateObject("ADSystemInfo")
Set objCurrentUser = GetObject("LDAP://" & objADSysInfo.UserName)

'Grab the user name
UserString = WshNetwork.UserName

'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

strUser = objADSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

strName = objUser.FullName
'Grab the computer name for use in add-on code later
strComputer = WshNetwork.ComputerName

if NOT objComputer.Description = WshNetwork.UserName & " (" & serviceTag & " - " & manufacturer & " " & model & ")" then
  objComputer.Description =  model & ", " & serviceTag & ", " & strName
  objComputer.SetInfo
end if

if NOT objUser.Description = WshNetwork.UserName & " (" & serviceTag & " - " & manufacturer & " " & model & ")" then
  objUser.Description =  strComputer & ", " & serviceTag & ", " & model 
  objUser.SetInfo
end if

wscript.echo strComputer & ", " & serviceTag & ", " & model

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
is there a place where I can add
Code:
if (ServiceTag="") then
DON'T add it to objUser.Description or objComputer.Description
end if

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
thought this might work but its not

Code:
if ServiceTag = "" then
  objComputer.Description =  model & "," & strName
  objComputer.SetInfo
  else
  objComputer.Description =  model & ", " & serviceTag & ", " & strName
  objComputer.SetInfo
end if

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Maybe at the top try:
serviceTag = [highlight #FCE94F]Trim([/highlight]replace(objSMBIOS.SerialNumber, ",", ".")[highlight #FCE94F])[/highlight]
 
Changed that line, fixed it thanks for all the help

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top