Powershell get SCOM alerts

While creating a script to do some basic server checks, I needed to retreive some information from SCOM to see if there are any active alerts for a particular server. I used the script below to gather my data.

Make sure you installed the Microsoft Management Operations Console so the Snapin is available to Powershell


#If the SCOM server is in a different domain, you could use "get-credential" to store your domain credentials
$credSCOM = Get-Credential
#SCOM server where to connect
$RMSServer = "SCOM.FQDN.Server"
#Which server does need to be checked on active alerts?
$TargetServer = "Server2CheckFQDN.Server"

if ((Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.EnterpriseManagement.OperationsManager.Client'}) -eq $null)
{
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction SilentlyContinue
}
#Credential part is only necessary when SCOM is in another domain.
if ((Get-ManagementGroupConnection | Where-Object {$_.ManagementServerName -eq $RMSServer}) -eq $null)
{
New-ManagementGroupConnection  $RMSServer -ErrorAction SilentlyContinue -Credential $credSCOM |Out-Null
}

if ((Get-PSDrive | Where-Object {$_.Name -eq 'Monitoring'}) -eq $null)
{
New-PSDrive -Name: Monitoring -PSProvider: OperationsManagerMonitoring -Root: \ -ErrorAction SilentlyContinue -ErrorVariable Err |out-null
if ($Err) { $(throw write-Host $Err) }
}

Set-Location Monitoring:\$RMSServer

#Check if server exists.
$complist = get-monitoringclass | Where-Object {$_.Name -eq ‘Microsoft.Windows.Computer’}   #Get the class Windows Computer and store it
$objects = get-monitoringobject -MonitoringClass $complist |Where-Object {$_.displayname -match $TargetServer}|select displayname -ErrorAction SilentlyContinue

if ($objects.DisplayName.Length -ne $null)
{
$alertlist = Get-Alert -Criteria "ResolutionState != 255" | where {$_.netbioscomputername -eq $TargetServer}| Select PrincipalName,Name,Description,TimeRaised,Severity
#If active alerts -eq $null
if ($AlertList -eq $null)
{
#Console output
write-host "Total Active Alerts : 0" -ForegroundColor "GREEN"
}
else
{
#Console output
write-host "Total Active Alerts: $($alertlist.Length)" -ForegroundColor "RED"
}
}
#If server doesn't exist
Else
{
#Console output
Write-Host "Server doesn't exist!" -ForegroundColor "RED"
}

#Close connections
Get-ManagementGroupConnection|Where-Object {$_.ManagementServerName -eq $RMSServer}|Remove-ManagementGroupConnection -Confirm:$false
}

VMware vCenter Log Insight: A new approach to analyzing unstructured machine data

At the moment I’m using Kiwi syslog for remote logging, since the announcement below, I will give the BETA test a try.

Announced on 11 June 2013

A new log analytics and management solution. vCenter Log Insight helps customers quickly search and analyze all their IT log data, providing them with meaningful, actionable operational insights.

Get more information:

VMware vCenter Log Insight: A new approach to analyzing unstructured machine data

Or see the Log Insight Datasheet

More related documents:

Log Analytics: Critical for Effective IT Operations
VMware vCenter Log Insight Delivers Immediate Value
End Your Data Center Logging Chaos with VMware vCenter Log Insight

CDP settings ESXi host

On an ESX host you could use the command below to display the CDP setting on a switch


<strong>esxcfg-vswitch</strong> [options] [vswitch[:ports]]

#Removed the settings that don't mention the ESXi settings.
-B|--set-cdp                Set the CDP status for a given virtual switch.
To set pass one of "down", "listen", "advertise", "both".
-b|--get-cdp                Print the current CDP setting for this switch.
-h|--help                   Show this message.

~ #
-b|--get-cdp                Print the current CDP setting for this switch.
~ #  esxcfg-vswitch -b vsw-vms01
listen
~ #  Setting the CDP settings to "Down"
~ #  esxcfg-vswitch -B down vsw-vms01
~ #  esxcfg-vswitch -b vsw-vms01
down

 

With Powershell you could instead make this function and use this like:

get-cdp -vmhost “MyHost”


function get-cdp {
<#
.SYNOPSIS
Grab CDP info from NIC's who are connected
.DESCRIPTION
This function greps some CDP info from the switch
.NOTES
Source:  Internet
Authors: XXX
.PARAMETER VMHost
An array of entity names. Only clusters, datacenters or
ESX hosts are allowed.
Wildcards are supported. (mutually exclusive with -dsName)
.PARAMETER whatif
When set, the function will only list output to the console
and not register the found vmx files
.EXAMPLE
PS> get-cdp -vmhost "MyHost"
#>
param($VMHost)
$vmh = Get-VMHost $VMHost
If ($vmh.State -ne "Connected") {
Write-Output "Host $($vmh) state is not connected, skipping."
}
Else {
Get-View $vmh.ID | `
% { $esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | `
% { foreach ($physnic in $_.NetworkInfo.Pnic) {
$pnicInfo = $_.QueryNetworkHint($physnic.Device)
foreach( $hint in $pnicInfo ){
# Write-Host $esxname $physnic.Device
if ( $hint.ConnectedSwitchPort ) {
$hint.ConnectedSwitchPort | select @{n="VMHost";e={$esxname}},@{n="VMNic";e={$physnic.Device}},DevId,Address,PortId
}
else {
}
}
}
}
}
}

XBMC How to add a new button to the Menu

How to add a new button to the Menu

Let’s say you want a button on the menu linking to your kids movies. the fist thing you need to do as add the folder containg the kids movies as a source in XBMC. This can be done by going to Videos > Files > Add videos

Alternatively, configure the sources.xml in your userdata folder as follows:

<sources>
<video>
<default pathversion="1"></default>
<source>
<name>Kids</name>
<path pathversion="1">smb://XBMC/Movies/Kids-Movies/</path>
</source>
</video>
<sources>

Adding a button is pretty easy, you can just use the code of one of the other buttons as a template.

<item id="19">
<label>Kids Movies</label>
<onclick>ActivateWindow(Videos,Kids)</onclick>
<icon>-</icon>
<thumb>-</thumb>
</item>

The only thing you need to take care of, is to use an unique ‘id’ for the button. In the code above, i’ve chosen to use id=”19″ as it’s not used elsewhere on the Home menu.

Now we have our code ready, we can simple insert it wherever we want in between the other menu buttons.