January 19, 2010

Script to ping a list of machines and export result in Excel File

Please create a file "MachineList.txt" and include machine name in this file.

copy the below script in notepad and save as "ping_result.vbs" file.
run the script in command prompt by specifying the same path.

run method: cscript ping_result.vbs

Script:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2

objExcel.Cells(1, 1).Value = "Machine Name"
objExcel.Cells(1, 2).Value = "Results"

Set Fso = CreateObject("Scripting.FileSystemObject")
Set InputFile = fso.OpenTextFile("MachineList.Txt")

Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine

Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)

objExcel.Cells(intRow, 1).Value = HostName

Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
End Select

intRow = intRow + 1
Loop

objExcel.Range("A1:B1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit

Script to connect to an SMS Provider

' Connect to an SMS Provider

Dim objSwbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim Location

set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

set objSWbemServices= objSWbemLocator.ConnectServer _
(".", "root\sms")

Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")

For Each Location In ProviderLoc
If Location.ProviderForLocalSite = True Then
Set objSWbemServices = objSWbemLocator.ConnectServer _
(Location.Machine, "root\sms\site_" + Location.SiteCode)
End If
Next

Script to update SMS Package

On Error Resume Next
Dim objSWbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim Location
Dim PackageID
Dim colPackages
Dim Package

'Enter the package ID of the package to be updated
PackageID = "PACKAGEID"

'To connect to the local SMS site's Provider by using SWbemLocator
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

Set objSWbemServices= objSWbemLocator.ConnectServer(".", "root\sms")
Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")

For Each Location In ProviderLoc
If Location.ProviderForLocalSite = True Then
Set objSWbemServices = objSWbemLocator.ConnectServer _
(Location.Machine, "root\sms\site_" + Location.SiteCode)
End If
Next

'To find the package ID in the SMS_Packages class and use the RefreshPkgSource Method to initiate update.
Set colPackages = objSWbemServices.ExecQuery _
("Select * from SMS_Package where PackageID = '" & PackageID & "'")

If colPackages.count <;>; 0 Then
For Each Package In colPackages
Package.RefreshPkgSource( )
WScript.Echo "Package '" & PackageID & "' Updated!"
Next
Else
WScript.Echo "Package '" & PackageID & "' Not Found!"
End If

January 18, 2010

The Configuration Manager 2007 Toolkit

The Configuration Manager 2007 Toolkit - Microsoft’s System Center Configuration Manager 2007 Toolkit contains a number of tools to help you manage and troubleshoot ConfigMgr 2007.
You can download the Toolkit from http://www.microsoft.com/downloads/details.aspx?familyid=948e477e-fd3b-4a09-9015-141683c7ad5f&displaylang=en (or go to http://www.microsoft.com/downloads and search for System Center Configuration Manager 2007 Toolkit).

Hardware Inventory Through WMI

ConfigMgr uses two MOF files to control hardware inventory:

SMS_Def.mof—Specifies the information reported to the management point during the client inventory retrieval cycle. The actual SMS_Def.mof file is not downloaded to the ConfigMgr client. Instead, the client receives changes to reporting class configuration as part of its machine policy.

Configuration.mof—Defines custom data classes the hardware inventory client agent will inventory. In addition to standard WMI classes, such as the Win32 classes, you can create data classes to provide inventory data that is accessible through WMI, such as data from the client’s system Registry. ConfigMgr clients download the Configuration.mof file as part of their machine policy retrieval cycle. Any changes are compiled and loaded into the WMI repository.

The ConfigMgr client stores its machine policy in the Root\CCM\Policy\Machine WMI namespace. You can use the WMI Object Browser from the WMI Administrative Tools to examine some to the inventory-related objects in this namespace. To launch the WMI Object Browser and connect to the ConfigMgr machine policy namespace, perform the following steps:

1.Select Start -> All Programs -> WMI Tools -> WMI Object Browser.
2.The WMI Object Browser opens a web browser and attempts to run an ActiveX control.
3.If your browser blocks the control, select the option Allow Blocked Content.
4.Change the entry in the Connect to namespace dialog box to Root\CCM\Policy\Machine and then click OK.
5.Click OK to accept the default logon settings.

Using the WMIDiag Utility

Using the WMIDiag Utility - SMS was one of the first applications to take advantage of WMI. At one time, SMS was often the only WMI management application running on many Windows machines. In those days, it was a common practice among SMS administrators to simply delete the repository when WMI errors were detected, and then restart WMI to re-create the repository. This is no longer a safe practice, because many applications depend on data stored in the repository. Moreover, WMI errors can result from many other problems in your environment and may have nothing to do with WMI itself.

Rather than deleting the repository, you should obtain the WMI Diagnosis Utility (WMIDiag) from the Microsoft download site (http://www.microsoft.com/downloads/details.aspx?familyid=d7ba3cd6-18d1-4d05-b11e-4c64192ae97d&displaylang=en, or go to http://www.microsoft.com/downloads and search for WMIDiag). WMIDiag can help you diagnose most WMI problems, and in many cases it provides detailed instructions on how to correct those problems.