Solved

Need help creating a script.

Posted on 2009-03-30
6
408 Views
Last Modified: 2012-05-06
I need to create a script that will go to every computer on the domain and grab a file from a folder.  ex.. C:\Program Files\Saazod\Saazmobile.ini.  Copy this file too a network share. \\servername\data\test and associate it with the computer name the file was copied from.. If this is possible I could use the assistance..

Thanks.
0
Comment
Question by:Compushare
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:rejoinder
ID: 24022485
Give this a shot.
Edit the following lines;
strFileName = "Saazmobile.ini"
strCurrFilePath = "C:\Program Files\Saazod\"
strNewFilePath = "\\servername\data\test\"
so as to match the path on the current file, filename and new path.

on error resume next
 
strFileName = "Saazmobile.ini"
strCurrFilePath = "C:\Program Files\Saazod\"
strNewFilePath = "\\servername\data\test\"
 
Const ADS_SCOPE_SUBTREE = 2
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
 
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name from 'LDAP://" & strDomain & "' Where objectCategory='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
    strComputer = objRecordSet.Fields("Name").Value
    set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    set objFile = objWMI.Get("Cim_Datafile='" & strCurrFilePath & strFileName & "'")
    intRC = objFile.Copy(strNewFilePath & strComputer & "-" & strFileName)
    if intRC <> 0 then
        'WScript.Echo "There was an error copying the file: " & intRC
    else
        'WScript.Echo "File copy successful"
    end if
    objRecordSet.MoveNext
Loop

Open in new window

0
 
LVL 1

Author Comment

by:Compushare
ID: 24029981
Should I copy this to notepad and create a batch file or should I use a power scripting editor program??
0
 
LVL 14

Expert Comment

by:rejoinder
ID: 24034707
Yes, copy the above and paste into notepad.  Save the file as <your-filename>.vbs.
Double click the file to run it.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Author Comment

by:Compushare
ID: 24054268
Im wanting to make it simple.. So how about renaming the saazmobile file to the computer name it was grabbed from and copying it into \\servername\shared\test folder??
0
 
LVL 14

Accepted Solution

by:
rejoinder earned 500 total points
ID: 24054398
To do that, all you need to do is change line 29 to this...
intRC = objFile.Copy(strNewFilePath & strComputer & ".ini")
0
 
LVL 1

Author Comment

by:Compushare
ID: 24063055
Ran the file..  get an error..
Windows Script Host
Line:  26
Char: 5
Error: Not Found
Code:  80041002
Source:  SWbemServicesEx
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 121
help with PowerShell script for registry permissions 8 82
Excel 2016 loop through 6 36
How can i open a .fxp file 3 29
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question