Monday, January 6, 2014

VBScript : Check Ping Status and Last boot time

Do you want to check status of multiple servers ? Do you want to know whether it is online ? or Do you want to check when was it rebooted? And on top of that you have 100+ servers to check... here is the solution.

Below is a VBScript which gives you Ping Status and last boot time for a list of servers.


Set objFSO = CreateObject("Scripting.FileSystemObject")
'Servers.txt is the input file. Save the server names in this file.
Set objTextFile = objFSO.OpenTextFile("C:\temp\Servers.txt",1,True)
'Result.txt is the output file
Set objOutputFile = objFSO.OpenTextFile("C:\temp\Result.txt",2,True)

Do While objTextFile.AtEndOfLine <> True
  strComputer = objTextFile.ReadLine


On Error resume Next
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strComputer & "'")

If oPing.StatusCode = 0 Then
   Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    Exit For

Next

WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
        Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) )
WMIDateStringToTime = CDate(Mid(dtmBootup, 9, 2) & ":" & _
        Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))

objOutputFile.WriteLine( strComputer & vbTab & WMIDateStringToDate & " " & WMIDateStringToTime & vbTab & "Able to Ping")

Else

objOutputFile.WriteLine( strComputer & vbTab & "Not Able to Ping")

End If

Set colOperatingSystems = nothing
Set objWMIService = Nothing
Set oWMI = Nothing
Set oPing = Nothing

Loop

Wscript.Echo "Done"

Note :

  • The script can be used to retrieve the values from servers in the same domain.
  • Save the script as a .vbs file and double click the same to run.
  • Servers.txt will store the list of servers for which output is required.
  • Result.txtis created which stored the output.
 Please write your queries in comment section.

VBScript to get Total Space details of drives on Multiple Servers

Hello everyone.. i am sharing one of my very first script used to get size details of drives on multiple servers in a domain. Hope it helps.

Dim strExcelPath, objExcel, objSheet, a, b, c
Const xlExcel7 = 39
 ' Spreadsheet file to be created.Result.xls will store the output.
strExcelPath = "c:\temp\Result.xls"

Set fso = CreateObject("Scripting.FileSystemObject")
' Server.txt is the input file for the script under C:\temp. Save server names in this file.
Set objInputFile = fso.OpenTextFile("c:\temp\Server.txt",1,True)


Set objExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
    On Error Goto 0
    Wscript.Echo "Excel application not found."
    Wscript.Quit
End If
On Error Goto 0
 ' Create a new workbook.
objExcel.Visible = True
objExcel.Workbooks.Add
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objSheet.Name = "Server Details"
' Format the spreadsheet.
objSheet.Range("A1:Z1").Font.Bold = True
intRow = 2
 
objExcel.Cells(1, 1).Value = "Hostname"
objExcel.Cells(1, 2).Value = "C:"
objExcel.Cells(1, 3).Value = "E:"
objExcel.Cells(1, 4).Value = "F:"
objExcel.Cells(1, 5).Value = "G:"
objExcel.Cells(1, 6).Value = "H:"
objExcel.Cells(1, 7).Value = "M:"
objExcel.Cells(1, 8).Value = "Q:"
objExcel.Cells(1, 9).Value = "T:"
objExcel.Cells(1, 10).Value ="I:"
 
Do While objInputFile.AtEndOfLine <> True

 strComputer = objInputFile.ReadLine
  objExcel.Cells(intRow, 1).Value = strComputer

 On Error resume Next
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oPing = oWMI.Get("Win32_PingStatus.Address='"& strComputer & "'")

If oPing.StatusCode = 0 Then
 
 
  Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_LogicalDisk")
   
     For Each objItem In colItems

        a = objItem.DeviceID
        b =  objItem.Size /1048576\1024 + 1
   
     Select Case a
         Case "C:"
             objExcel.Cells(intRow, 2).Value = b
         Case "E:"
             objExcel.Cells(intRow, 3).Value = b
         Case "F:"
             objExcel.Cells(intRow, 4).Value = b
         Case "G:"
             objExcel.Cells(intRow, 5).Value = b
         Case "H:"
             objExcel.Cells(intRow, 6).Value = b
         Case "M:"
             objExcel.Cells(intRow, 7).Value = b
         Case "Q:"
             objExcel.Cells(intRow, 8).Value = b
         Case "T:"
             objExcel.Cells(intRow, 9).Value = b
         Case "I:"
             objExcel.Cells(intRow, 10).Value = b
     End Select
   
     
Next
intRow = intRow + 1
End If

Set objWMIService = Nothing
Set colItems = Nothing
Set objItem = Nothing


 Loop

' Save the spreadsheet and close the workbook.
 ' Specify Excel7 File Format.
objExcel.ActiveWorkbook.SaveAs strExcelPath, xlExcel7
objExcel.ActiveWorkbook.Close
 ' Quit Excel.
objExcel.Application.Quit
 ' Clean Up
Set objSheet = Nothing
Set objExcel = Nothing
Wscript.Echo "Done"


Note :
  • The script can be used to retrieve the values from servers in the same domain.
  • Save the script as a .vbs file and double click the same to run.
  • Server.txt will store the list of servers for which output is required.
  • Result.xls is created which stored the output.
 Please write your queries in comment section.

MSIEXEC



Microsoft Windows Installer (Windows 7/2008).
Syntax
      MSIEXEC /Option RequiredParameter [OptionalParameter]

Install Options
   Install or configure a product:
      MSIEXEC /package Product.msi
      MSIEXEC /i Product.msi

   Administrative install, Install a product on the network:
      MSIEXEC /a Product.msi

   Advertise a product to all users:
      MSIEXEC /j m Product.msi [/t TransformList] [/g LanguageID]

   Advertise a product to current user:
      MSIEXEC /j u Product.msi [/t TransformList] [/g LanguageID]

   Uninstall the product:
      MSIEXEC /uninstall Product.msi
      MSIEXEC /x Product.msi
      MSIEXEC /uninstall ProductCode
      MSIEXEC /x ProductCode

Display Options

   Quiet mode, no user interaction
      /quiet

   Unattended mode - progress bar only
      /passive

   Set user interface level: None
      /qn

   Set user interface level: Basic UI
      /qb

   Set user interface level: Reduced UI
      /qr

   Set user interface level: Full UI (default)
      /qf

   Help information
      /help
               
Restart Options
   Do not restart after the installation is complete:
      /norestart

   Prompt the user for restart if necessary:
      /promptrestart

   Always restart the computer after installation:
      /forcerestart
            
Logging Options
   /le Logfile  Log All error messages
   /lw Logfile  Log Non-fatal warnings
   /li Logfile  Log Status messages
   /la Logfile  Log Start up of actions
   /lr Logfile  Log Action-specific records
   /lu Logfile  Log User requests
   /lc Logfile  Log Initial (UI) parameters
   /lm Logfile  Log Out-of-memory or fatal exit information
   /lo Logfile  Log Out-of-disk-space messages
   /lp Logfile  Log Terminal properties
   /lv Logfile  Log Verbose output
   /lx Logfile  Log Extra debugging information

   /l* Logfile  Log all information, except for v and x options
   /log Logfile Equivalent of /l*

   /l+ Logfile  Append to an existing log file.
   /l! Logfile  Flush each line to the log.

Update Options
   Apply update(s)
      /update [;Update2.msp]

   Remove update(s) for a product:
      /uninstall [;Update2.msp] /package
               
Repair Options - Repair a previously installed product
   /fp          Repair/fix - replace missing files
   /fo          Repair/fix - replace Older files(default)
   /fe          Repair/fix - replace older or Equal date files
   /fd          Repair/fix - replace Different version files
   /fc          Repair/fix - replace files based on Checksum differences
   /fa          Repair/fix - replace All files
   /fu          Repair/fix - rewrite HKCU registry(default)
   /fm          Repair/fix - rewrite HKLM registry(default)
   /fs          Repair/fix - recreate shortcuts(default)
   /fv          Repair/fix - rewrite local cache from source

Set Public Properties
        [PROPERTY=PropertyValue]
Windows installer (and msiexec) have been updated with each major release of Windows (from 2000 to XP to 2008 R2) Windows Installer redistributables are available at the Microsoft Download Center.
Registry Keys:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
Product codes - the ProductCode for each application is a GUID that can be retrieved with a WMI query in VBScript or PowerShell, Get-WmiObject Win32_Product will return the IdentifyingNumber which is the Product code:
PS C:\> gwmi Win32_Product -Filter "Name LIKE 'Paint.net v3%'"
Do not use the domain controller SYSVOL folder as a Windows Installer installation point, doing so may result in the following error when you attempt to run the Windows Installer (.msi) package:
This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.
This is because the SYSVOL folder is created with the SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS attribute, which prevents it from being exclusively locked by Windows Installer. Having locked files on a SYSVOL will create Active Directory directory service synchronization problems.
Examples:
Install:
msiexec /i "C:\Install\ss64app.msi"

UnInstall:
msiexec /uninstall "{5AFF6499-63BA-4A36-83B2-8D256404AC3D}" /log "C:\install\ss64app.txt"
or remotely with psexec
psexec \\$workstation -s msiexec /uninstall "{5AFF6499-63BA-4A36-83B2-8D256404AC3D}" /log "C:\install\ss64app.txt"

CHKDSK Utility


If you're encountering persistent errors and need to run the CHKDSK utility in attempt to recover or fix any data or installation errors, simply follow these steps:
Note that running the CHKDSK utility can take up to several hours, so ensure you are able to leave your computer scanning for a large amount of time before attempting the following.

Windows 8 Users

  • Starting from the Desktop, hold down the Windows key and press E to open Windows Explorer.
  • Right-click the hard drive and select Properties.
  • Select the Tools tab.
  • Click the "Check" button under "Error checking"
  • Click the "Scan drive" button.
  • Click the "Schedule disk check" option and reboot.
  • After CHKDSK has finished running, try to start up and run your game to see if the issue was corrected.
Windows 7 Users
  • Hold down the Windows key and press E to open Windows Explorer.
  • Right-click the hard drive and select Properties.
  • Select the Tools tab.
  • Click the "Check now" button under "Error checking"
  • Check both boxes under "Check disk options"
  • Click the "Start" button.
  • Click the "Schedule disk check" option then reboot.
  • After CHKDSK has finished running, try to start up and run your game to see if the issue was corrected.
 CHKDSK can fix Error Events with id 55.


What is an event ID 55? Let’s start by looking at the error:

Event Type: Error
Event Source: NTFS
Event ID: 55
Description:
The file system structure on disk is corrupt and unusable. Please run the chkdsk utility on the volume "Drive_letter:"


Explanation
The file system structure on the volume listed in the message might be corrupt because of one or more of the following reasons:
  • The disk might have bad sectors.
  • I/O requests issued by the file system to the disk subsystem might not have been completed successfully.
   
User Action
Check the state of the file system and repair it if necessary.
To check the state of the file system
  1. Click Start, click Run, and then, in the Open box, type
    cmd
  2. To determine whether the volume is corrupt, at the command prompt, type
    chkntfs Drive:

    • If the message “Drive_letter: is dirty” is displayed, the volume is corrupt. In this case, repair the file system.
    • If the message “Drive_letter: is not dirty” is displayed, the volume is not corrupt and no further action is required.
To repair the file system
  1. Save any unsaved data and close any open programs.
  2. Restart the computer.
    The volume is automatically checked and repaired when you restart the computer.
Alternatively, you can run the Chkdsk tool from the command prompt without shutting down the computer first.
  1. Click Start, click Run, and then type
    cmd
  2. At the command prompt, type

  3. chkdsk /XDrive:
    Chkdsk runs and automatically repairs the volume.
If the following message appears, type Y.
“Cannot lock current drive. Chkdsk cannot run because the volume is in use by another process. Would you like to schedule this volume to be checked the next time the system restarts?”
The next time the computer is started, Chkdsk will automatically run.
If the NTFS 55 message appears regularly, for example daily or weekly, run Chkdsk using the /R command-line option. This option allows Chkdsk to locate bad sectors on the hard disk.