Jump to content

Script to Copy Folder Based on Wmi Result


Recommended Posts

Hi I was wonder if possabley some one Might be able point right direction of script

What I wound like to do Is Vb Script that will copy A folder Based on Reslutes Of Wmi Query?

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery( _

"SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems

Wscript.Echo "-----------------------------------"

Wscript.Echo "Win32_BaseBoard instance"

Wscript.Echo "-----------------------------------"

Wscript.Echo "Product: " & objItem.Product

Next

give me the Model number What wound like to do be able to spefic Folder Based on The Diffent Resluts Returned By This query

Any Help or Input Wound Be Greatly Appricated :> Ty In Advanced am not much script guru so am look for Advice Of More Knowledgeable Person

Link to comment
Share on other sites


What you need is a general If Then Else Statement.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_BaseBoard",,48)
For Each objItem in colItems
If objitem.Product = "<SearchString>" Then
<Do Something>
Else
<Do Something different>
End If
Next

Link to comment
Share on other sites

Hi Yowl Thank for quick reply

Please not that my scribt abilty is lacking

Correct if am wrong sure am colitem it text string

so what you say if get right i just keep put

I just put if colitem string for each? so i can listed one by one

like right now wmi script has return sting txt say 967ma being mainboard model

but on diffent broad say diffent name

I can just put if then string

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery( _

"SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems

If objitem.Product = "<SearchString>" Then

<Do Something>

Else

<Do Something different>

End If

Next

I guess also can just put any vb script code copy file like this exsample i found on

I need copy folder from network share include sub folders

Set FSO =CreateObject("scripting.FileSystemObject")

FSO.CopyFolder "\\Pta-srv\sjvwebsite\*", "c:\Backup\" ,True

FSO.CopyFile "\\Pta-srv\sjvwebsite\*", "c:\Backup\", True

MsgBox"BackUp completed, Goodbye", vbInformation, "Script Informer"

something like that ?

Anyways Thanks for Quick response

Link to comment
Share on other sites

If you want to copy and have a diplay on it progress then something like this would be better.

This will copy the source folder and all of it contents, with a diplay of progress.

 Dim Shl :Set Shl = CreateObject("Shell.Application")
Dim Folder, Source, Target
Source = "\\COMPUTER_NAME_OR _IP\FOLDER_NAME\COPY_THIS_FOLDER"
Target = "E:\FOLDER_NAME"
Set Folder = Shl.NameSpace(Target)
Folder.CopyHere Source

Link to comment
Share on other sites

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery( _

"SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems

If objitem.Product = "776295U" Then

Dim Shl :Set Shl = CreateObject("Shell.Application")

Dim Folder, Source, Target

Source = "\\COMPUTER_NAME_OR _IP\FOLDER_NAME\COPY_THIS_FOLDER"

Target = "E:\FOLDER_NAME"

Set Folder = Shl.NameSpace(Target)

Folder.CopyHere Source

Else

Wscript.Echo "Product: " & objItem.Product

End If

Next

is this remotely right?

i know need change folder

Link to comment
Share on other sites

  • 2 weeks later...

Hi i got some of it figure out copy file part based on broad i if = statement going?seem be have troblue get second

this what got so far how wound anythey if product = fm10 or diffent id ?????? i try few way but i can,nt seem to get it maybe i need else or next statement ? Thank all in advnaced i got some of work out

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colItems = objWMIService.ExecQuery( _

"SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems

If objitem.Product = "440BX Desktop Reference Platform" Then

Set FSO =CreateObject("scripting.FileSystemObject")

FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True

Else MsgBox "I don't know what mainboard this is no driverse will be copyed you must manual install"

End If

Next

Link to comment
Share on other sites

Perhaps try this script.

Dim ChkItem, colItems, FSO, objItem, objWMIService, StrItem, StrResult
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'-> Array To Hold The Items
StrItem = Array( _
"Benicia", _
"440BX Desktop Reference Platform", _
"ANOTHER BASEBOARD1", _
"ANOTHER BASEBOARD2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems
For Each ChkItem In StrItem
If InStr(LCase(objitem.Product), LCase(ChkItem))Then
StrResult = objitem.Product
End If
Next
Next

If Len(StrResult) >= 1 Then
Set FSO =CreateObject("scripting.FileSystemObject")
MsgBox "Found This Match " & StrResult
FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True
Else
MsgBox "There is no match in the list"
End If

Link to comment
Share on other sites

Hi Gunsmokeinman :> i see you Vancouver am from vancouver island

I was wonder if you maybe give me exsample with two item already in it?

I can seem to graspe what i am missing

I am guess the number beside broad name? is identify for item

and that

If Len(StrResult) >= 1 Then

Set FSO =CreateObject("scripting.FileSystemObject")

MsgBox "Found This Match " & StrResult

FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True

Else

and this wound be line it run if want to do more wound just add that twice and change number to diffent broad id?

I hope not bug Thank for reply just try get idea behind this am not super script guy

Thank For input so far

my question do also need else statment for if not right model or cound just have one if not found it say it once so script does.nt need

line for each item that not in listed

maybe am missing something does script you have do one item based more one broadid

I need to do diffent things base on id is found

Edited by andyasselin
Link to comment
Share on other sites

The Array hold a list of MB I used mine the one you posted and 2 Made Up Ones

StrItem = Array( _
"Benicia", _
"440BX Desktop Reference Platform", _
"ANOTHER BASEBOARD1", _
"ANOTHER BASEBOARD2")

It Then Starts The WMI Querry and Then Anther Loop To Compares Strings From The StrItem Array

 'Loop One WMI
For Each objItem in colItems
'Loop 2 StrItem Array
For Each ChkItem In StrItem
'Compare The String
If InStr(LCase(objitem.Product), LCase(ChkItem))Then
StrResult = objitem.Product
End If
Next
Next

This is to check if the querry came back with a result. It checks the lengh of StrReults if it over 1

character then it will produce Found This Match And The Match Object. The Else means StrResult

came back with less then 1 character, or No Match was found in the Array.

   If Len(StrResult) >= 1 Then
Set FSO =CreateObject("scripting.FileSystemObject")
MsgBox "Found This Match " & StrResult
FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True
Else
MsgBox "There is no match in the list"
End If

Link to comment
Share on other sites

I think am go crazy with this

okay so you say each array get number like one 1 2 3 etc??

or does it use name like id broad to ideinfty arraw

then i change the string If Len(StrResult) >= 2 Then to the number or broad name ?

right now script work one broad but second one does seem to copy or try to copy same folder from fristed one

Dim ChkItem, colItems, FSO, objItem, objWMIService, StrItem, StrResult

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

'-> Array To Hold The Items

StrItem = Array( _

"Benicia", _

"776295U", _

"ANOTHER BASEBOARD1", _

"ANOTHER BASEBOARD2")

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BaseBoard",,48)

For Each objItem in colItems

For Each ChkItem In StrItem

If InStr(LCase(objitem.Product), LCase(ChkItem))Then

StrResult = objitem.Product

End If

Next

Next

If Len(StrResult) >= 2 Then

Set FSO =CreateObject("scripting.FileSystemObject")

MsgBox "Found This Match " & StrResult

FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True

Else

MsgBox "There is no match in the list"

End If

If Len(StrResult) >= 3 Then

Set FSO =CreateObject("scripting.FileSystemObject")

MsgBox "Found This Match " & StrResult

FSO.CopyFolder "\\Server\installshare\drivers\VMWARE\*", "c:\DRIVERS\" ,True

Else

MsgBox "There is no match in the list"

End If

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...