Power of Windows Management Instrumentation (WMI)
Allot of new SysAdmins are getting carried away with PowerShell Scripting.. For me the big difference between PowerShell and Old School forms of Scripting is that. 1:) PowerShell has a eco-system for integration with other Application like vSphere. The disadvantage is that Powershell needs to be available on the Windows Server and these Plugins need to be installed and Remoting is a pain and not straight forward.
If your tasks is to perform work on multiply windows servers, WMI is the best option and Powershell really is a overkill.
In this blog, I am going to document the various scripts that SysAdmin can use day to day:
WMI uses Distributed Component Object Model (DCOM) and Windows Remote Management (WimRM). DCOM is the most powerful part of Windows.
Reference
- About WMI – http://msdn.microsoft.com/en-us/library/windows/desktop/aa384642(v=vs.85).aspx
- WMI Administrator Tools – http://www.microsoft.com/en-au/download/details.aspx?id=24045
- WMI Browsing Tool – http://technet.microsoft.com/en-us/library/cc181099.aspx
- WMI Code Creator – http://www.microsoft.com/en-au/download/details.aspx?id=8572
- DCOM – http://www.dmtf.org/standards/cim
- Scripting Tools and Utilities – http://technet.microsoft.com/en-au/scriptcenter/dd823314.aspx
- Learn WMI – http://technet.microsoft.com/en-us/scriptcenter/dd742341.aspx
- ScriptoMatic – http://www.microsoft.com/en-us/download/details.aspx?id=12028
- WMI Administrator – http://www.microsoft.com/en-au/download/details.aspx?id=24045
- CIM Studio – http://technet.microsoft.com/en-us/library/cc181062.aspx
Remote Example Script
[source]
@echo off
:start
for /f %%I in (serverlist.txt) do call :run %%I
goto :end
:run
echo %1
wmic /node:%1 service where StartMode="Auto" list brief /format:htable > \\##\share\#%1_report.txt
goto :eof
[/source]
[source]
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const CONVERT_TO_LOCAL_TIME = True
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
Set DeviceListFile = FileSystemObject.OpenTextFile(CurrentDirectory & "\DeviceList.txt", ForReading)
Do Until DeviceListFile.AtEndOfStream
Devicename = DeviceListFile.ReadLine
If Trim(Devicename) <> "" Then
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
dtmStartDate.SetVarDate dateadd("n", -10, now)’ CONVERT_TO_LOCAL_TIME
Set winmgmts = GetObject("winmgmts:\\" & Devicename & "\root\cimv2")
Set Win32_OperatingSystem = winmgmts.ExecQuery ("Select * from Win32_OperatingSystem")
For each Instance in Win32_OperatingSystem
Wscript.Echo Devicename & ", " & UtcDateToString(Instance.LastBootUpTime)
Next
End if
Loop
DeviceListFile.Close
Function UtcDateToString(UtcFormattedDate)
UtcDateToString = CDate(Mid(UtcFormattedDate, 5, 2) & "/" & Mid(UtcFormattedDate, 7, 2) & "/" & Left(UtcFormattedDate, 4) & " " & Mid (UtcFormattedDate, 9, 2) & ":" & Mid(UtcFormattedDate, 11, 2) & ":" & Mid(UtcFormattedDate, 13, 2))
End Function
[/source]