charast
asked on
VBscript code to retrieve the systemdrive of a remote server
hello Experts,
I have already created a script that will copy a file from a specific directory on several servers on my network to another specific server. This is used for data collection.
my current issue is that we have inherited several servers that actually have the systemdrive as V:\ or Z:\ instead of the normal and customary C:\.
my original script only accounts for the standard C:\ which is just hardcoded into a string.
and runs against a text file list of servers.
now, here is my problem for which I need your help:
I need to modify this script to determine the %systemdrive% of the REMOTE server (which is determined by the serverlist.txt file), and use that to populate my variable to copy the file no matter if the systemdrive is C, V or whatever....
One other thing to note is that whatever method used to determine the systemdrive of the remote server, it has to work on NT4 (yea, yea, I know!! ) and higher.
I tried to use:
strSysDrive = oShell.ExpandEnvironmentSt rings("%WI NDIR%")
however, that just returns the systemdrive of the local machine that the script is being ran from. I couldnt figure out how to pull the data from my serverlist in my loop.
I have already created a script that will copy a file from a specific directory on several servers on my network to another specific server. This is used for data collection.
my current issue is that we have inherited several servers that actually have the systemdrive as V:\ or Z:\ instead of the normal and customary C:\.
my original script only accounts for the standard C:\ which is just hardcoded into a string.
and runs against a text file list of servers.
now, here is my problem for which I need your help:
I need to modify this script to determine the %systemdrive% of the REMOTE server (which is determined by the serverlist.txt file), and use that to populate my variable to copy the file no matter if the systemdrive is C, V or whatever....
One other thing to note is that whatever method used to determine the systemdrive of the remote server, it has to work on NT4 (yea, yea, I know!! ) and higher.
I tried to use:
strSysDrive = oShell.ExpandEnvironmentSt
however, that just returns the systemdrive of the local machine that the script is being ran from. I couldnt figure out how to pull the data from my serverlist in my loop.
' ========================================================
'
' Title: Copy file from remote server
' Author: Christopher
' Originally created: 08/28/09
' Original path:
' Description: This script will copy a specified file to a specified
' destination on remote servers that is retrieved from
' a text file.
'
' ========================================================
'=============variables===================================
Const strLogfile = "c:\scripts\NetworkFilecopy.LOG"
Const ForReading = 1
Const OverwriteExisting = True
Const intForWriting = 2
Const Createfile = True
Dim objLogfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
'textfile name and location that contains the servers to connect to
Set objFile = objFSO.OpenTextFile("C:\Scripts\Serverlist.txt")
Set objNetwork = CreateObject("wscript.network")
strDestinationFile = "D:\EMC_Grab_Storage\"
'=============body========================================
'opens logfile for writing
On Error Resume Next
Set objLogfile=fso.Opentextfile(strLogfile,intForWriting,Createfile)
objLogfile.writeline
objLogfile.writeline "---------------------------------------------------------------------"
objLogfile.writeline "Script started by " & objNetwork.username & " on " & Now
objLogfile.writeline "---------------------------------------------------------------------"
objLogfile.writeline vbCrLf
'parses text file of servers and copies the specified file to it
Do Until objFile.AtEndOfStream
strComputer = objFile.ReadLine
strSourceFile = "\\" & strComputer & "\C$\Windows\emcreports\collection\zip\*.zip"
objFSO.CopyFile strSourceFile, strDestinationFile, OverwriteExisting
'error handling
If err.number <> 0 Then
objLogfile.writeline "** Error connecting to server " & strComputer & "error # " & err.number & err.description
err.clear
Else
objLogfile.writeline "Successfully copied file from server " & strComputer
End If
Loop
'finalize and close log file
objLogfile.writeline vbCrLf
objLogfile.writeline "---------------------------------------------------------------------"
objLogfile.writeline "Script completed at " & Now
objLogfile.writeline "---------------------------------------------------------------------"
objLogfile.close
WScript.ECHO "Script complete. Output logged to " & strLogfile
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Great, glad that helped, and thanks for the feedback.
~bp
~bp
ASKER
although it will not work with my NT4 servers, I was able to work with this and instead of using
strSystemDrive = Left(objOS.SystemDrive, 1)
I used
strSystemDrive = Left(objOS.WindowsDirector
which gives me the same result for this script and also allows me to use the whole string for one of my other scripts which needs the string for the windows directory as well.
Thank you again! I knew I could depend on someone here to help me out on this one!