Monday, September 19, 2011

Collect Patch Information of Cluster Hosts for last 180 Days.

Requirement: You have n MS 2008 clusters having m hosts, you need to find out the patch status (Installation Date, Installed By) of all the hosts in last 180 days.

Solution:
A. Collect the list of all nodes (n*m) of the clusters.
1. Log on to any one of the cluster.
2. Create a file servername.txt, which contains the list of all clusters.
3. Open Powershell, and type PS C:\Import-Module Failover Cluster;
4. Create a ps1 file Clusternode.ps1 having the following code,
foreach ( $server in Get-Content .\servername.txt)
{
write "------------"
write $server
write "------------"
get-clusternode -cluster $server
}
5. Run the .\ClusterNode.ps1 | out-file clusternodestatus.txt
6. The file clusternodestatus.txt will contain the list of all the cluster nodes.

B. Run Powershell Script against all the nodes to get patch information.

1. Create a file servername.txt having list of all the cluster nodes.
2. Create a ps1 file PatchStatus.ps1 having the following code,
foreach ($Server in Get-Content .\servername.txt)
{
#write "-----------------------------------------------------------------"
write $Server
#get-hotfix -computer $Server
get-hotfix -computer $Server | ? {$_.InstalledOn} | where { (Get-date($_.Installedon)) -gt (get-date).adddays(-180) }
}
3. Run .\PatchStatus.ps1 | out-file StatusReport.txt
4. The File StatusReport.txt will contain the patch information,
Sample Report:

Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
XXXX1 Security Update KB2446709 NT AUTHORITY\SYSTEM 4/22/2011 12:00:00 AM
XXXX2 Security Update KB2476490 NT AUTHORITY\SYSTEM 6/18/2011 12:00:00 AM
XXXX3 Security Update KB2478661 NT AUTHORITY\SYSTEM 6/18/2011 12:00:00 AM


Note: Some sample query.

List All installed patches:

PS C:>get-hotfix | select Description, Hotfixid

List all patches that are installed in last 30 days:

PS C:> get-hotfix | ? {$_.InstalledOn} | where { (Get-date($_.Installedon)) -gt (get-date).adddays(-30) }

List all patches installed on specific date:

PS C:> get-hotfix | ? {$_.InstalledOn} | where { (Get-date($_.Installedon)) -gt (get-date 10/31/2009) }

Query for a specific hotfix by providing hotfix ID(KB12345 format):

PS C:> get-hotfix | ? {$_.HotfixID -match ” KB975025″ }

List all hotfixes installed by administrator account:

PS C:> get-hotfix | ? {$_.InstalledBy -match “administrator” }

You can adopt the above queries and run against remote machine by passing the computer name shown like below.
PS C:> get-hotfix -Computer remotecomp | ? {$_.InstalledOn} | where { (Get-date($_.Installedon)) -gt (get-date).adddays(-30) }

Note: Install Powershell in Win2K8 core: Ref: http://techibee.com/powershell
Thanks and Regards,
Subhag Ghosh
You can contact me on subhag.ghosh@gmail.com

Monday, September 5, 2011

List HP Services on Multiple Machines

@echo off
for /f %%C in (ServerName.txt) do (
echo %%C
sc \\%%C query type= service state= all | find "hp" /I >> HpServices.txt
)