shankjai
asked on
Vb Script, to copy particular folder with subdirectories from multiple servers to a common location with unique server names as their respective folders
i have to copy PKI folder from Remote servers, i hav admin access, so when do \\servername i can copy the contents of VPHOME folder. Â For ur easy understanding, i can tell u, PKI is a certification file of Symantec Antivirus Servers, each server is having a share named VPHOME, inside VPHOME share, u may find, Grc.dat file, and a folder name PKI, inside PKI u have subdirectories and files.
d: Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "The backup files of remote server should be in D drive of the master server, im running the code from"
cd\
cd NewPKI Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Folder to backup the PKI contents"
cd ServerGroupName             "ServerName to be replaced everytime it runs"
md ServerName                   "Need to create a directory in the name of the server it replaces"
cd ServerName                       "Changing the directory to the respective servername folder for backup of PKI folder"
copy \\ServerName\VPHOME\grc.da t     " in the server share, u have VPHOME as share, from which i hav to backup GRC.DAT file alone"
Xcopy \\ServerName\VPHOME\pki /E /Y Â Â Â Â Â Â " Inside PKI folder, u may have 4 subdirectories, several files of some 10 to 20 Kb files"
In the above code, the ServerName need to be replaced with the name of the servers in the list of CSV / Txt  file.
in the CSV/txt file, u may have the server names like this.
S.No.     ServerName     ServerGroupName
1 Â Â Â Â Â Â Â Â JSBXXX Â Â Â Â Â Â Â Â ASIA
2. Â Â Â Â Â Â HSBDYU Â Â Â Â Â Â Â Â ASIA
3. Â Â Â Â Â Â FFSSLF Â Â Â Â Â Â Â Â ASIA
4. Â Â Â Â Â Â DFLSSF Â Â Â Â Â Â Â Â ASIA
After we run a script, the folder map will b like this
D:\NewPki\Asia\JSBXXX\PKI\ ...\..
D:\NewPki\Asia\HSBDYU\PKI\ ...\..
D:\NewPki\Asia\FFSSLF\PKI\ ...\..
D:\NewPki\Asia\DFLSSF\PKI\ ...\..
going further, the servergroupname also changes, like consider it as location based. such as America. We have to create seperate folder for America as   d:\NewPKI\America\....., the servernames will b different in that location.
--
P.S. I have gone thru this https://www.experts-exchange.com/questions/22612350/VB-Script-copy-files-from-mulitple-computer-to-single-destination-adding-date-and-computername.html?sfQueryTermInfo=1+copi+file+from+remot+script+server thread, but it only concentrates on Log files, so i dont know how to convert them for my PKI folders in VB script.
pls help me; My mail id shankjai@yahoo.com
d: Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "The backup files of remote server should be in D drive of the master server, im running the code from"
cd\
cd NewPKI Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Folder to backup the PKI contents"
cd ServerGroupName             "ServerName to be replaced everytime it runs"
md ServerName                   "Need to create a directory in the name of the server it replaces"
cd ServerName                       "Changing the directory to the respective servername folder for backup of PKI folder"
copy \\ServerName\VPHOME\grc.da
Xcopy \\ServerName\VPHOME\pki /E /Y Â Â Â Â Â Â " Inside PKI folder, u may have 4 subdirectories, several files of some 10 to 20 Kb files"
In the above code, the ServerName need to be replaced with the name of the servers in the list of CSV / Txt  file.
in the CSV/txt file, u may have the server names like this.
S.No.     ServerName     ServerGroupName
1 Â Â Â Â Â Â Â Â JSBXXX Â Â Â Â Â Â Â Â ASIA
2. Â Â Â Â Â Â HSBDYU Â Â Â Â Â Â Â Â ASIA
3. Â Â Â Â Â Â FFSSLF Â Â Â Â Â Â Â Â ASIA
4. Â Â Â Â Â Â DFLSSF Â Â Â Â Â Â Â Â ASIA
After we run a script, the folder map will b like this
D:\NewPki\Asia\JSBXXX\PKI\
D:\NewPki\Asia\HSBDYU\PKI\
D:\NewPki\Asia\FFSSLF\PKI\
D:\NewPki\Asia\DFLSSF\PKI\
going further, the servergroupname also changes, like consider it as location based. such as America. We have to create seperate folder for America as   d:\NewPKI\America\....., the servernames will b different in that location.
--
P.S. I have gone thru this https://www.experts-exchange.com/questions/22612350/VB-Script-copy-files-from-mulitple-computer-to-single-destination-adding-date-and-computername.html?sfQueryTermInfo=1+copi+file+from+remot+script+server thread, but it only concentrates on Log files, so i dont know how to convert them for my PKI folders in VB script.
pls help me; My mail id shankjai@yahoo.com
cd\
cd NewPKI "Folder to backup the PKI contents"
cd ServerGroupName "ServerName to be replaced everytime it runs"
md ServerName "Need to create a directory in the name of the server it replaces"
cd ServerName "Changing the directory to the respective servername folder for backup of PKI folder"
copy \\ServerName\VPHOME\grc.dat " in the server share, u have VPHOME as share, from which i hav to backup GRC.DAT file alone"
Xcopy \\ServerName\VPHOME\pki /E /Y " Inside PKI folder, u may have 4 subdirectories, several files of some 10 to 20 Kb files"
IF %NETID% == 172.16.9 xcopy "\\%computername%\VPhome\*.*" "\\pkiserver\vphome\ASIA\%computername%\NewPKI\*.*" /D /E /I /R /Y
IF %NETID% == 172.16.10 xcopy "\\%computername%\VPhome\*.*" "\\pkiserver\vphome\AMERICA\%computername%\NewPKI\*.*" /D /E /I /R /Y
IF %NETID% == 172.16.11 xcopy "\\%computername%\VPhome\*.*" "\\pkiserver\vphome\MEXICO\%computername%\NewPKI\*.*" /D /E /I /R /Y
ASKER
Option Explicit
Dim strFile, objSh , errorFile, objErr1
Dim  strSrc1, strSrc2, strDest, bolFlag
'Enter the Server name into the Computers.txt file, one entry per line
strFile = "SymantecPSList.txt"
Dim objFSO, objTS, strComputer, objOuts, objFolder, objErr, objFile, i,strLine, objPing, objStatus,colComputer, oComputer
Dim iDR, sName
'specify filename and folder path for file/folder to be copied
strSrc1="\vphome\pki"
strSrc2 = "\vphome\grc.dat"
'specify target destination
strDest="\\mainserver\Fina l\New Folder\ "
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objSh = CreateObject("WScript.Shel l")
'Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set objFile = objFSO.OpenTextFile("Syman tecPSList. txt", ForReading)
Const ForReading = 1
Const ForAppending = 8
Â
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
  Redim Preserve arrFileLines(i)
  arrFileLines(i) = objFile.ReadLine
  i = i + 1
Loop
objFile.Close
Â
' Â Â Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
' Â Â Set objSh = CreateObject("WScript.Shel l")
  If objFSO.FileExists("output. txt") Then
Â
  Else
    Set objFile = objFSO.CreateTextFile("out put.txt")
  End If
 Â
  Set objFile = Nothing
 Â
''Checks whether Server list is available
If objFSO.FileExists(strFile) Then
 Â
  Set objFile = objFSO.OpenTextFile("outpu t.txt", ForAppending)
 Â
  objFile.WriteLine("------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------")
  objFile.WriteLine("Ping Results of the Servers in the server List as on  " & now())
  objFile.WriteLine("_______ __________ __________ __________ __________ __________ __________ __________ __________ _______")
  objFile.WriteLine("")
 Â
' For Each strLine in arrFileLines
' Â Â Set objPing = GetObject("winmgmts:{imper sonationLe vel=impers onate}")._
' Â Â Â Â ExecQuery("select * from Win32_PingStatus where address = '"_
' Â Â Â Â Â Â & strLine &Â "'")
' Â Â For Each objStatus in objPing
' Â Â Â Â If IsNull(objStatus.StatusCod e) or objStatus.StatusCode<>0 Then
' Â Â Â Â Â Â objFile.WriteLine("Server: "Â & strLine &Â " is not reachable" &Â vbTab &Â objStatus.ProtocolAddress)
' Â Â Â Â Else
' Â Â Â Â Â Â objFile.WriteLine("Server: "Â & strLine &Â " is reachable *********************"& vbTab &Â objStatus.ProtocolAddress)
'
'For Each strLine in arrFileLines
'WScript.Echo ResolveIP("strLine")
'
'Function ResolveIP(strComputer)
'' Â Â On Error Resume Next
'
' Â Â Dim wmiQuery, objWMIService, objPing, objStatus
' Â Â
' Â Â wmiQuery = "Select * From Win32_PingStatus Where "Â & _
' Â Â "Address = '" &Â strComputer &Â "'"
' Â Â
' Â Â Set objWMIService = GetObject("winmgmts:\\.\ro ot\cimv2")
' Â Â Set objPing = objWMIService.ExecQuery(wm iQuery)
' Â Â
' Â Â For Each objStatus in objPing
' Â Â Â Â If IsNull(objStatus.StatusCod e) Or objStatus.Statuscode<>0 Then
' Â Â Â Â Â Â ResolveIP = "Computer is Unreachable!"
' Â Â Â Â Else
' Â Â Â Â Â Â ResolveIP = objStatus.ProtocolAddress
' Â Â Â Â End If
' Â Â Next
'End Function
'
'Next
For Each strLine in arrFileLines
If Reachable("strLine") Then
  WScript.Echo "Computer" & strLine & "is Reachable"
Else
  WScript.Echo "Computer is Unreachable!"
End If
Function Reachable(strComputer)
' Â Â On Error Resume Next
  Dim wmiQuery, objWMIService, objPing, objStatus
 Â
  wmiQuery = "Select * From Win32_PingStatus Where " & _
  "Address = '" & strComputer & "'"
 Â
  Set objWMIService = GetObject("winmgmts:\\.\ro ot\cimv2")
  Set objPing = objWMIService.ExecQuery(wm iQuery)
 Â
  For Each objStatus in objPing
    If IsNull(objStatus.StatusCod e) Or objStatus.Statuscode<>0 Then
      Reachable = False 'if computer is unreacable, return false
    Else
      Reachable = True 'if computer is reachable, return true
    End If
  Next
End Function
'Set colComputer = GetObject("winmgmts:\\" &Â strLine &Â "\root\cimv2").ExecQuery(" Select DomainRole, Domain from Win32_ComputerSystem")
'For Each oComputer in colComputer
'iDR = oComputer.DomainRole
'sName = oComputer.Domain
'Next
'
'If iDR = 0 Or iDR = 2 Then
'objFile.WriteLine "Computer is in workgroup "Â & sName
'Else
'objFile.WriteLine "Computer is in domain "Â & sName
'End If
Â
    End If
  Next
Next
   Â
End If
' objFile.Close
Set objFile = Nothing
WScript.Echo "************************* ********** ********** ********** ********** ********** *"
WScript.Echo "PKI Folder  Backup in progress, Please wait till the program says 'COMPLETE'"
WScript.Echo "************************* ********** ********** ********** ********** ********** *"
WScript.Echo ""
  Set objTS = objFSO.OpenTextFile(strFil e)
  Set objOuts = objFSO.CreateTextFile("PKI backupServ erList.txt ")
  Set objErr = objFSO.CreateTextFile("Err orList.txt ")      Â
 Â
  objOuts.WriteLine("------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------")
  objOuts.WriteLine("List of Server Names whose PKI backup was done successfully on  " & now())
  objOuts.WriteLine("_______ __________ __________ __________ __________ __________ __________ __________ __________ _______")
  objOuts.WriteLine("")
 Â
  objErr.WriteLine("-------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -----")
  objErr.WriteLine("List of Server Names whose PKI backup was not done as on  " & now())
  objErr.WriteLine("________ __________ __________ __________ __________ __________ __________ __________ __________ ______")
  objErr.WriteLine("")
 Â
Do Until objTS.AtEndOfStream
    strComputer = objTS.ReadLine
'Folder created with the respective server names  Â
' Â Â Â Â If objFSO.FolderExists("\\mai nserver\Fi nal\New Folder\" &Â strComputer) Then
Set objPing = GetObject("winmgmts:{imper sonationLe vel=impers onate}")._
    ExecQuery("select * from Win32_PingStatus where address = '"_
      & strComputer & "'")
 For Each objStatus in objPing
  If IsNull(objStatus.StatusCod e) or objStatus.StatusCode<>0 Then
      objErr.WriteLine("Server: " & strComputer & " is not reachable" & vbTab & objStatus.ProtocolAddress)
  Else
      objOuts.WriteLine("Server: " & strComputer & " is reachable *********************"& vbTab & objStatus.ProtocolAddress)
           'End If
           'Next
          If objFSO.FolderExists("D:\Ne wPki" & strComputer) Then
     Â
              WScript.Echo "Folder " & strComputer & " already exists, Skipping the server"
              '   objErr.WriteLine("Server: " & strComputer & " is reachable *********************" & vbTab & objStatus.ProtocolAddress)
 Â
             'Server list which are skipped.
               objErr.WriteLine ("Server Name: " & strComputer & " Folder already exists hence skipped PKI backup")
               objErr.WriteLine("Server: " & strComputer & " is reachable *********************"& vbTab & objStatus.ProtocolAddress)
              Â
      Â
          Else
       Â
            Set objFolder   = objFSO.CreateFolder(strCom puter)
              'PKI folders are copied along with GRC.dat file in the created server folders  Â
            '       objSh.Run "Xcopy.exe \\" & strComputer & "\Share\Test " & " " & "\\mainserver\Final\New Folder\" & strComputer & " /e /y"
            '       objSh.Run "Xcopy.exe \\" & strComputer & "\test2\sam.cab" & " " & "\\mainserver\Final\New Folder\" & strComputer & "  /y"
                 Â
' Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â objSh.Run "Xcopy.exe "Â & strSrc1 &Â " "Â & strDest &Â strComputer &Â " /e /y"
' Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â objSh.Run "Xcopy.exe "Â & strSrc2 &Â " "Â & strDest &Â strComputer &Â " Â /y"
            '      Â
            ' '       objSh.Run "Xcopy.exe C:\test C:\Backup /E /Y"
                 Â
                objSh.Run "Xcopy.exe \\" & strComputer & strSrc1 & " " & strDest & "\" & strComputer & " /e /y"
                objSh.Run "Xcopy.exe \\" & strComputer & strSrc2 & " " & strDest & "\" & strComputer & "  /y"
            '       objSh.Run "Xcopy.exe \\mainserver\test" & " " &  "\\mainserver\Final\New Folder"  & " /e /y"
             Â
            '     WScript.Echo "Tried the above link for " & strComputer
            WScript.Echo "Folder Created in the Name of :" & strComputer
           Â
                  objOuts.WriteLine ("PKI Backup done for the Server Name: " & strComputer)
       Â
          End If
  End If
Next
Loop
 Â
' Â Â End If
objTS.Close
 objOuts.Close
 objErr.Close  Â
 'objFile.Close
WScript.Echo "output of Backup servers will be in PKIbackupServerList.txt file"
WScript.Echo "output of skipped servers will be in ErrorList.txt file"
WScript.Echo
WScript.Echo "Complete :o)"
Dim strFile, objSh , errorFile, objErr1
Dim  strSrc1, strSrc2, strDest, bolFlag
'Enter the Server name into the Computers.txt file, one entry per line
strFile = "SymantecPSList.txt"
Dim objFSO, objTS, strComputer, objOuts, objFolder, objErr, objFile, i,strLine, objPing, objStatus,colComputer, oComputer
Dim iDR, sName
'specify filename and folder path for file/folder to be copied
strSrc1="\vphome\pki"
strSrc2 = "\vphome\grc.dat"
'specify target destination
strDest="\\mainserver\Fina
Set objFSO = CreateObject("Scripting.Fi
Set objSh = CreateObject("WScript.Shel
'Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile("Syman
Const ForReading = 1
Const ForAppending = 8
Â
Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
  Redim Preserve arrFileLines(i)
  arrFileLines(i) = objFile.ReadLine
  i = i + 1
Loop
objFile.Close
Â
' Â Â Set objFSO = CreateObject("Scripting.Fi
' Â Â Set objSh = CreateObject("WScript.Shel
  If objFSO.FileExists("output.
Â
  Else
    Set objFile = objFSO.CreateTextFile("out
  End If
 Â
  Set objFile = Nothing
 Â
''Checks whether Server list is available
If objFSO.FileExists(strFile)
 Â
  Set objFile = objFSO.OpenTextFile("outpu
 Â
  objFile.WriteLine("-------
  objFile.WriteLine("Ping Results of the Servers in the server List as on  " & now())
  objFile.WriteLine("_______
  objFile.WriteLine("")
 Â
' For Each strLine in arrFileLines
' Â Â Set objPing = GetObject("winmgmts:{imper
' Â Â Â Â ExecQuery("select * from Win32_PingStatus where address = '"_
' Â Â Â Â Â Â & strLine &Â "'")
' Â Â For Each objStatus in objPing
' Â Â Â Â If IsNull(objStatus.StatusCod
' Â Â Â Â Â Â objFile.WriteLine("Server:
' Â Â Â Â Else
' Â Â Â Â Â Â objFile.WriteLine("Server:
'
'For Each strLine in arrFileLines
'WScript.Echo ResolveIP("strLine")
'
'Function ResolveIP(strComputer)
'' Â Â On Error Resume Next
'
' Â Â Dim wmiQuery, objWMIService, objPing, objStatus
' Â Â
' Â Â wmiQuery = "Select * From Win32_PingStatus Where "Â & _
' Â Â "Address = '" &Â strComputer &Â "'"
' Â Â
' Â Â Set objWMIService = GetObject("winmgmts:\\.\ro
' Â Â Set objPing = objWMIService.ExecQuery(wm
' Â Â
' Â Â For Each objStatus in objPing
' Â Â Â Â If IsNull(objStatus.StatusCod
' Â Â Â Â Â Â ResolveIP = "Computer is Unreachable!"
' Â Â Â Â Else
' Â Â Â Â Â Â ResolveIP = objStatus.ProtocolAddress
' Â Â Â Â End If
' Â Â Next
'End Function
'
'Next
For Each strLine in arrFileLines
If Reachable("strLine") Then
  WScript.Echo "Computer" & strLine & "is Reachable"
Else
  WScript.Echo "Computer is Unreachable!"
End If
Function Reachable(strComputer)
' Â Â On Error Resume Next
  Dim wmiQuery, objWMIService, objPing, objStatus
 Â
  wmiQuery = "Select * From Win32_PingStatus Where " & _
  "Address = '" & strComputer & "'"
 Â
  Set objWMIService = GetObject("winmgmts:\\.\ro
  Set objPing = objWMIService.ExecQuery(wm
 Â
  For Each objStatus in objPing
    If IsNull(objStatus.StatusCod
      Reachable = False 'if computer is unreacable, return false
    Else
      Reachable = True 'if computer is reachable, return true
    End If
  Next
End Function
'Set colComputer = GetObject("winmgmts:\\" &Â strLine &Â "\root\cimv2").ExecQuery("
'For Each oComputer in colComputer
'iDR = oComputer.DomainRole
'sName = oComputer.Domain
'Next
'
'If iDR = 0 Or iDR = 2 Then
'objFile.WriteLine "Computer is in workgroup "Â & sName
'Else
'objFile.WriteLine "Computer is in domain "Â & sName
'End If
Â
    End If
  Next
Next
   Â
End If
' objFile.Close
Set objFile = Nothing
WScript.Echo "*************************
WScript.Echo "PKI Folder  Backup in progress, Please wait till the program says 'COMPLETE'"
WScript.Echo "*************************
WScript.Echo ""
  Set objTS = objFSO.OpenTextFile(strFil
  Set objOuts = objFSO.CreateTextFile("PKI
  Set objErr = objFSO.CreateTextFile("Err
 Â
  objOuts.WriteLine("-------
  objOuts.WriteLine("List of Server Names whose PKI backup was done successfully on  " & now())
  objOuts.WriteLine("_______
  objOuts.WriteLine("")
 Â
  objErr.WriteLine("--------
  objErr.WriteLine("List of Server Names whose PKI backup was not done as on  " & now())
  objErr.WriteLine("________
  objErr.WriteLine("")
 Â
Do Until objTS.AtEndOfStream
    strComputer = objTS.ReadLine
'Folder created with the respective server names  Â
' Â Â Â Â If objFSO.FolderExists("\\mai
Set objPing = GetObject("winmgmts:{imper
    ExecQuery("select * from Win32_PingStatus where address = '"_
      & strComputer & "'")
 For Each objStatus in objPing
  If IsNull(objStatus.StatusCod
      objErr.WriteLine("Server: " & strComputer & " is not reachable" & vbTab & objStatus.ProtocolAddress)
  Else
      objOuts.WriteLine("Server:
           'End If
           'Next
          If objFSO.FolderExists("D:\Ne
     Â
              WScript.Echo "Folder " & strComputer & " already exists, Skipping the server"
              '   objErr.WriteLine("Server: " & strComputer & " is reachable *********************" & vbTab & objStatus.ProtocolAddress)
 Â
             'Server list which are skipped.
               objErr.WriteLine ("Server Name: " & strComputer & " Folder already exists hence skipped PKI backup")
               objErr.WriteLine("Server: " & strComputer & " is reachable *********************"& vbTab & objStatus.ProtocolAddress)
              Â
      Â
          Else
       Â
            Set objFolder   = objFSO.CreateFolder(strCom
              'PKI folders are copied along with GRC.dat file in the created server folders  Â
            '       objSh.Run "Xcopy.exe \\" & strComputer & "\Share\Test " & " " & "\\mainserver\Final\New Folder\" & strComputer & " /e /y"
            '       objSh.Run "Xcopy.exe \\" & strComputer & "\test2\sam.cab" & " " & "\\mainserver\Final\New Folder\" & strComputer & "  /y"
                 Â
' Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â objSh.Run "Xcopy.exe "Â & strSrc1 &Â " "Â & strDest &Â strComputer &Â " /e /y"
' Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â objSh.Run "Xcopy.exe "Â & strSrc2 &Â " "Â & strDest &Â strComputer &Â " Â /y"
            '      Â
            ' '       objSh.Run "Xcopy.exe C:\test C:\Backup /E /Y"
                 Â
                objSh.Run "Xcopy.exe \\" & strComputer & strSrc1 & " " & strDest & "\" & strComputer & " /e /y"
                objSh.Run "Xcopy.exe \\" & strComputer & strSrc2 & " " & strDest & "\" & strComputer & "  /y"
            '       objSh.Run "Xcopy.exe \\mainserver\test" & " " &  "\\mainserver\Final\New Folder"  & " /e /y"
             Â
            '     WScript.Echo "Tried the above link for " & strComputer
            WScript.Echo "Folder Created in the Name of :" & strComputer
           Â
                  objOuts.WriteLine ("PKI Backup done for the Server Name: " & strComputer)
       Â
          End If
  End If
Next
Loop
 Â
' Â Â End If
objTS.Close
 objOuts.Close
 objErr.Close  Â
 'objFile.Close
WScript.Echo "output of Backup servers will be in PKIbackupServerList.txt file"
WScript.Echo "output of skipped servers will be in ErrorList.txt file"
WScript.Echo
WScript.Echo "Complete :o)"
ASKER
The above code i fixed and run it in my server, its working. but the query state in the above code "'Set colComputer = GetObject("winmgmts:\\" &Â strLine &Â "\root\cimv2").ExecQuery(" Select DomainRole, Domain from Win32_ComputerSystem")" throws error while run in windows 2003 environment. hence i commented the Ping status codes.
any idea how to check, whether the server is reachable, if reachable output the IP address and hostname of the server which are done with PKI backup.
P.S. For your question about the schedule backup on servers. The network is huge n the servers are large. any change in the schedule task has to go through proper procedure. this will take a month or two to proceed. I dont want the management to involve in approval / query. thats y i would like to run a vbscript with the list of server names in my network. Moreover, a copy of PKI folder for each server is enough, no need to take the backup again and again as scheduled.
any idea how to check, whether the server is reachable, if reachable output the IP address and hostname of the server which are done with PKI backup.
P.S. For your question about the schedule backup on servers. The network is huge n the servers are large. any change in the schedule task has to go through proper procedure. this will take a month or two to proceed. I dont want the management to involve in approval / query. thats y i would like to run a vbscript with the list of server names in my network. Moreover, a copy of PKI folder for each server is enough, no need to take the backup again and again as scheduled.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I guess if you have the code working...and you just want to see if a machine is online. Use the code below. Â Of course sub strComputer for strHost
http://www.petri.co.il/forums/showthread.php?t=348
http://www.petri.co.il/forums/showthread.php?t=348
'********************************************************************
'* Function IsPingable(strHost)
'*
'* Returns True or False based on the output from ping.exe
'********************************************************************
Function IsPingable(strHost)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c ping.exe -n 3 -w 1000 " & strHost)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
'Wscript.Echo "Reply received."
IsPingable = True
Exit Do
End If
Loop
If (IsPingable <> True) Then
IsPingable = False
End If
End Function
example ...
xcopy "\\JSBXXX\vphome\*.*" "d:\NewPKI\asia\JSBXXX\vph
also, have you considered creating a single batch file to be run as a scheduled task from all servers ?..as opposed to maintaining a script when you have to add and remove servers...
first you set a global environment variable on every server...using this code as a startup script...
This creates a permanent system variable you can use to identify the subnet a server is on, and use it as a variable.
http://www.microsoft.com/technet/scriptcenter/csc/scripts/desktop/settings/cscds060.mspx
example batch script to run on any remote server..
IF %NETID% == 172.16.9 xcopy "\\%computername%\VPhome\*
IF %NETID% == 172.16.10 xcopy "\\%computername%\VPhome\*
IF %NETID% == 172.16.11 xcopy "\\%computername%\VPhome\*
let me know what you think...