Ying Li at myITforum.com

PowerShell & System Center

Powershell script to check if opsware agent is installed and running

Here is a powershell script to check if opsware agent installed and running. It uses the .NET class I mentioned in my previous post[System.ServiceProcess.ServiceController]:: to get the service status from remote computer.

#$erroractionpreference = "SilentlyContinue"

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1) = "Machine Name"
$c.Cells.Item(1,2) = "Opsware Agent"
$c.Cells.Item(1,3) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

foreach ($strComputer in get-content C:\MachineList.Txt)
{
 $c.Cells.Item($intRow,1)  = $strComputer

Function CheckOpsware
{
 $OpswareSVC = [System.ServiceProcess.ServiceController]::GetServices($strComputer) | where{$_.name -eq 'OpswareAgent'}
 If($OpswareSVC.status -eq "Running")
  {
  $c.Cells.Item($intRow,2) = "Running"
 }
 ElseIf($OpswareSVC.status -eq "Stopped")
 {
  $c.Cells.Item($intRow,2) = "Stopped" 
 }
 Else
 {
  $c.Cells.Item($intRow,2) = "Opsware Agent may not be installed"
 }
}

CheckOpsware

$c.Cells.Item($intRow,3) = Get-Date

$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()

Posted: Mar 20 2007, 10:26 AM by yli628 | with no comments
Filed under:

Comments

No Comments