Sunday, April 3, 2011

VB Script for checking computers in a text file are turned on

Below is a handy script for checking Pc's in a text file are turned on and you can connect to the Admin share. 

'Check Computers in c:\temp\computers.txt are turned on
'And you can access admin share

Option Explicit
Dim objDictionary, objFSO, objTextFile, i, strNextLine
Dim objItem, objFolder, strCantConnect

' Read Arguments from a Text File
Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\temp\computers.txt", ForReading)
i = 0
WScript.Echo "Verify you can connect to Computers in c:\temp\computers.txt"
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop

For Each objItem in objDictionary
    Set objFSO = CreateObject("Scripting.FileSystemObject")
  If objFSO.FolderExists("\\"& objDictionary.Item(objItem) & "\Admin$") Then
      Set objFolder = objFSO.GetFolder("\\" & objDictionary.Item(objItem) & "\Admin$")
  Else
      WScript.Echo "Can't Connect to " & objDictionary.Item(objItem) & chr(10) & chr(13) & "Please verify it is contactable via DNS and you have Admin rights"
      strCantConnect = "1"
  End If
Next
If strCantConnect = "1" Then
WScript.Echo "Script Finished!"
Else WScript.Echo "All Desktops are Switched on!"
End if

2 comments:

  1. How can I use this script to check with Local Admin or any other specific user name

    ReplyDelete
  2. You could call the script using psexec which will allow you to pass username and password.
    http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
    PSexec -u domain\username -p password wscript c:\temp\CheckComputersOn.vbs

    ReplyDelete