March 31, 2012

SCCM Query to find how many sites have PXE service point enabled?

This report will help to identify all the PXE service point enabled within any SCCM environment.

Select vs.sitecode,vs.sitename,vs.servername,vss.role from v_Site vs, v_SiteSystemSummarizer vss
where vs.SiteCode=vss.SiteCode and
vss.Role like 'SMS PXE Service Point'

November 30, 2011

Script to monitor specific service on multiple Windows Servers

Hi,

Please find the script for service monitoring on multiple windows servers and do let me know your feedback.

how to run?
-create a separate folder name it anything
-create a txt file name as compname.txt (in case of me, I have used this name under script)
-Input all servers name inside the compname.txt file
-copy and paste the script in notepad and save it as .vbs
-double click on the .vbs file
-log file with current date and time will be automatically generated and you can see the service status inside.


'script to monitor specific service on multiple Windows Servers
'script created by Atul Mishra
'pls check the automatically generated log file for service status
Dim sDate
Dim strTime
Dim strDate
Dim strState
Dim strDataIn           'Input list from text file
Dim aryData                     'Array to hold input stream
Dim iCounter            'Iterative loop counter
dim strOUT                      'Output file
Dim oWshShell           'Windows shell script 
Dim objFSO                      'Scripting File System 
Dim objFile                     'Open text file
Dim strFilePath         'Path to current directory
Dim strServiceName      'Name of service to be checked
 
Set oWshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFilePath = objFSO.GetAbsolutePathName(".")
 
'Get Service Name
strServiceName = InputBox("Enter name of service...", "Service name input")
 
'Read file into a variable
strDataIn = f_r(strFilePath & "\compname.txt")

'Split into an array
aryData = Split(strDataIn,vbCrLf) 
oWshShell.Popup Ubound(aryData) + 1 & " Hosts/Addresses in list." & Chr(13) & "Scan is underway.",2,"Notice",64
sDate = Date
strTime = Now
StrDate = DatePart("m",sDate) & "." & DatePart("d",sDate) & "." & Hour(strTime) & "." & Minute(strTime)
set strOUT = objFSO.CreateTextFile(strFilePath & "\SERVICEResults." & strDate & ".log")
strOUT.WriteLine strServiceName & " query results:"
strOUT.WriteBlankLines (2)
For iCounter = 0 to Ubound(aryData)
 aryData(iCounter) = Trim(aryData(iCounter)) ' clean "white space"
If GetService(aryData(iCounter), strServiceName) then
        strOUT.Write aryData(iCounter) & ",Installed : " & strState & vbcrlf
Else
        strOUT.Write aryData(iCounter) & ",Service not present" & vbcrlf
End if
Next
strOUT.Close 
set strOUT = nothing
set objFSO = nothing
oWshShell.Popup "Scan processing complete.",5,"Notice",64
WScript.quit
   
'Given the path to a file,  this function will return entire contents
Function f_r(FilePath)
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
  f_r = FSO.OpenTextFile(FilePath,1).ReadAll
End Function
'Returns True or False based on the status of the specified Service
Function GetService(strComputer, strSrvce)
On Error Resume Next
Dim objWMIService
Dim colListOfServices
Dim objService
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
    ("Select DisplayName,State from Win32_Service Where Name = '" & strSrvce & "'")
If Err.Number <> 0 Then
  GetService = "False"
  Err.Clear
Else
For Each objService in colListOfServices
  GetService  = "True"
  strState  = objService.State
Next
End If
End Function

Please let me know your views.
Cheers!

Script to fix WSUS client issue automatically

Hi Everyone,

Please find the script to make your infrastructure environment 100% patch compliant and do let me know the feedback. It will help admins to fix WSUS client issue and can help them to automate the fix and reduce no of tickets :)

Here we go,

'script will use wmi to do the following on a local computer
'Created by Atul Mishra
' Supported OS - Win XP, Win7, Win 2003 server, Win 2008 server
'1. Stop the Automatic Updates Service
'2. Delete the %WINDIR%\softwaredistribution folder
'3. Delete the HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate keys and subkeys.
'4. Start the Automatic updates Service
'5. Send a wuauclt.exe /resetauthorization /detectnow command to sysem
'6. Initiate software update scan cycle actions
dim objFSO, objShell, objTempFile, objTS
dim sCommand, sReadLine
dim oCPAppletMgr 'Control Applet manager object.
dim oClientAction 'Individual client action.
dim oClientActions 'A collection of client actions.
'dim bReturn
set objShell = WScript.CreateObject("Wscript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
'----------------Stop Automatic Updates Service--------------------
'
'
'On Error Resume Next
' NB strService is case sensitive.
strService = " 'wuauserv' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colListOfServices
objService.StopService()
Next
WScript.Echo "Service has been stopped"
'
'
'
'----------------- Delete Folder and Reg Keys --------------------------------
strExe = "cmd.exe /C rmdir %WINDIR%\SoftwareDistribution /S /Q && cmd.exe /C REG DELETE HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate /f"
' Connect to WMI
'
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
WScript.Echo "The software Distribution Folder and WindowsUpdate regsitry keys have been deleted."
'------------------ Start Automatic Update Service -------------
'On Error Resume Next
' NB strService is case sensitive.
strService = " 'wuauserv' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colListOfServices
objService.StartService()
Next
WScript.Echo "Service has been Started on " & strcomputer

'-------------- Force Checking to WSUS server by issueing a wuauclt.exe /resetauthorization /detectnow ------------

strExe = "cmd.exe /C wuauclt.exe /resetauthorization /detectnow"
' Connect to WMI
'
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
WScript.Echo "Force checkin has been sent. Process Complete."
'Initiate software update scan cycle actions
'Get the Control Panel manager object.
set  oCPAppletMgr=CreateObject("CPApplet.CPAppletMgr")
if err.number <> 0 then
    Wscript.echo "Couldn't create control panel application manager"
    WScript.Quit
end if
'Get a collection of actions.
set oClientActions=oCPAppletMgr.GetClientActions
if err.number<>0 then
    wscript.echo "Couldn't get the client actions"
    set oCPAppletMgr=nothing
    WScript.Quit
end if
'Display each client action name and perform it.
For Each oClientAction In oClientActions
    if oClientAction.Name = "Software Updates Assignments Evaluation Cycle" then
        wscript.echo "Performing action " + oClientAction.Name
        oClientAction.PerformAction
    end if
next
set oClientActions=nothing
set oCPAppletMgr=nothing

If you have some more thoughts, please share. I would like to script your thoughts to automate the administration.

Cheers!

June 6, 2011

Status message query to find out all sccm servers with specific component status

select stat.*, ins.*, att1.*, stat.Time from  SMS_StatusMessage as stat left join SMS_StatMsgInsStrings as ins on ins.RecordID = stat.RecordID left join SMS_StatMsgAttributes as att1 on att1.RecordID = stat.RecordID where stat.Component = "SMS_EXECUTIVE" and stat.Time >= ##PRM:SMS_StatusMessage.Time## order by stat.Time DESC

Cheers!

April 27, 2011

Collection query to list all clients where advertisement was not succeeded

We can create a collection with the below dynamic query to list all clients where specific advertisement was not successful. All you need to change the advert ID and use it to your production environment to make management happy by reports.

SMS_R_SYSTEM.ResourceID not in (select SMS_ClientAdvertismentStatus.ResourceID from SMS_ClientAdvertisementStatus where SMS_ClientAdvertisementStatus.AdvertisementID = "ADV20408" and SMS_ClientAdvertisementStatus.laststatusmessageID in (10009))

Cheers!

WMI Commands to perform SCCM actions

Here we go; WMIC is tool which can be used as command line and perform below sccm actions -

Disable Software-Distribution:
WMIC /namespace:\\root\ccm\policy\machine\requestedconfig path ccm_SoftwareDistributionClientConfig  CREATE ComponentName="Disable SWDist",Enabled="false",LockSettings="TRUE",PolicySource="local",PolicyVersion="1.0" ,SiteSettingsKey="1" /NOINTERACTIVE

Re-Activate Software-Distribution:
WMIC /namespace:\\root\ccm\policy\machine\requestedconfig path ccm_SoftwareDistributionClientConfig  WHERE ComponentName="Disable SWDist" delete /NOINTERACTIVE

Trigger Hardware Inventory:
WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000001}" /NOINTERACTIVE

Trigger Software Inventory:
WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000002}" /NOINTERACTIVE

Trigger DataDiscoverRecord (DDR) update:
WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000003}" /NOINTERACTIVE

Force a FULL HW Inventory on next HW-Inv Schedule:
WMIC /namespace:\\root\ccm\invagt path inventoryActionStatus where InventoryActionID="{00000000-0000-0000-0000-000000000001}" DELETE /NOINTERACTIVE

Repair SMS/SCCM Agent on a remote client:
WMIC /node:%MACHINE% /namespace:\\root\ccm path sms_client CALL RepairClient

Repair a list (all clients listed in clients.txt) of remote SMS/SCCM Agents:
WMIC /node:@clients.txt /namespace:\\root\ccm path sms_client CALL RepairClient

Cheers!