Skip to content

Latest commit

 

History

History
214 lines (127 loc) · 7.3 KB

SCOMManagement.md

File metadata and controls

214 lines (127 loc) · 7.3 KB

Management Packs

Management Group Information

Database and Datawarehouse Information

Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup' -Name DatabaseServerName,DatawarehousedbServerName | Select-Object  DatabaseServerName,DatawarehousedbServerName | ft -AutoSize

Management Server Information

Get-SCOMManagementServer | Select-Object -Property HealthState,DisplayName,Version,IsGateway ,IPAddress ,ActionAccountIdentity,@{Name="AgentCount";Expression={(($_).GetAgentManagedComputers()).Count}},InstallTime | ft -AutoSize

Group Management

Getting Group of a computer

[cmdletbinding()]
Param(

[string]$ComputerName,
[string]$ManagementServer

)
Import-Module OperationsManager
if (!(Get-SCOMManagementGroupConnection).Isactive) {

New-SCOMManagementGroupConnection -ComputerName $ManagementServer

}

$ComputerObjectID = Get-SCOMClass -Name Microsoft.Windows.Computer | Get-SCOMClassInstance | where {$_.Name -eq $ComputerName}

$Groups = Get-SCOMGroup
$groups | ForEach-Object {

if ((($_).GetRelatedMonitoringObjects().Where({$_.GetLeastDerivedNonAbstractClass().Name -eq 'Microsoft.Windows.Computer'})).Name -contains $ComputerName) {
"$computerName is member of $($_.DisplayName)"
}

}

References

The following script line lists references used by unsealed managementpacks which helps in migrating management groups to list which mps needs to be insalled on the new management group.

((get-scommanagementpack).where({$_.Sealed -eq $false})).References.Value.Name | Select-Object -Unique | Sort-Object

Agent Management

Agent and Management Server management scripts.

Runs HSLockodwn on multiple dcs. Requires Powershell Remoting.

 
Import-Module OperationsManager
 
$ProblemDCs="dc1","dc2","dc3"
 
$AddScriptBlock={
set-location "C:\Program Files\Microsoft Monitoring Agent\Agent"
.\HSLockdown.exe /A 'NT AUTHORITY\SYSTEM'
get-service -Name HealthService | Restart-Service -Verbose
}
 
Invoke-Command -ScriptBlock $AddScriptBlock -ComputerName $ProblemDCs

Returns the unhealthy Health Service Watchers

 
Get-SCOMClass -DisplayName "Health Service Watcher" | Get-SCOMClassInstance | where {$_.HealthState -eq 'Error'}
 

Agent and Gateway Failover

The following line lists scom Gateways with their failover servers.

Get-SCOMGatewayManagementServer | Select-Object -Property DisplayName, @{Name="PrimaryServer"; Expression={($_.GetPrimaryManagementServer()).DisplayName}},@{Name="FailOverServer"; Expression={($_.GetFailoverManagementServers()).DisplayName}}

List of Primary and Failover MS for SCOM agents

Get-SCOMAgent | select-object -Property DisplayName, PrimaryManagementServerName, @{Name='FailoverMS';Expression={($_.GetFailoverManagementServers()).Name}}

Updating Agents

Following line updates the agent to UR7 using PSSession

Invoke-Command -session $2016rtms -ScriptBlock {invoke-expression 'C:\Windows\system32\msiexec.exe /p C:\temp\ur7\KB4492182-AMD64-Agent.msp /qn'}

Following line gets the latest success event for agent update using pssesion

Invoke-Command -session $2016rtms -ScriptBlock {Get-EventLog -LogName Application -Source MsiInstaller -InstanceId 1022 -Message *System?Center?2016?Operations?Manager?Update?Rollup ?7* -Newest 1 | Select-Object -Property TimeGenerated,Message}

Alerts

Alert related powershell scrirps

Returns top 20 active alerts in scom console

Get-SCOMAlert | where ResolutionState -eq 0 | Group-Object -Property Name | Sort-Object -Property Count -Descending  | Select-Object -Property Count,Name -First 20

Lists Top 20 Active Alerts and if they are Monitor Based. But has a bug if theres "," in alert Name then the alert name is truncted(split). Dont worry the Remaining part is handled:)

Get-SCOMAlert | where ResolutionState -eq 0 | Group-Object -Property Name,IsMonitorAlert | Sort-Object -Property Count -Descending  | Select-Object -Property Count, @{Name="AlertName";Expression={$result=$_.Name -split "," ;$result[0] }}  ,@{Name="IsMonitorAlert";Expression={$result=$_.Name -split "," ;$result|ForEach-Object {if ($_ -match '(True|False)'){$Matches[1]}} }} -First 20

Gets the count per day of the specified alert

Get-SCOMAlert | where {$_.Name -eq 'Server Performance Exception' -and $_.ResolutionState -eq 0} | Select-Object -Property @{Name="Date";Expression={"{0:yyyy-MM-dd}" -f $_.TimeRaised}}, NetbiosComputerName | Group-Object -Property Date | Sort-Object -Property Name -Descending | Select-Object -Property Name,Count

Gets the count of alerts generated by each computer

Get-SCOMAlert | where {$_.Name -eq 'Server Performance Exception' -and $_.ResolutionState -eq 0}  | Group-Object -Property NetbiosComputerName | Sort-Object -Property Count -Descending |Select-Object -Property Name,Count

Run the below line on the management server to figure out which agents are connected.

 Get-NetTCPConnection -LocalPort 5723 | Format-Table -Property @{Name="LocalDNS";Expression={(resolve-dnsname $_.LocalAddress).NameHost}},LocalPort,@{Name="RemoteDNS";Expression={(resolve-dnsname $_.RemoteAddress).NameHost}},RemotePort,@{Name="ProcessName";Expression={(Get-Process -PID ($_.OwningProcess)).Name}},state 
 

Top Servers restarted in the last 7 days.

$rule=get-scomrule -DisplayName "Collection Rule for Windows Restarted Events"
Get-SCOMEvent -Rule $rule | where {$_.TimeGenerated -gt (Get-Date).AddDays(-7) } | Group-Object -Property LoggingComputer  |Sort-Object -Property Count -Descending | Select-Object -first 10 -Property Count,Name

Lists the servers with the computer not reachable monitor in red. Script referring to Kevin Holman but a couple modifications.

$MonitorColl = @()
$MonitorColl = New-Object "System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]"

$objects = get-scomclass -DisplayName "Health Service Watcher" | Get-SCOMClassInstance
$monitor = Get-SCOMMonitor -DisplayName 'Computer Not Reachable'

ForEach ($object in $objects)
{
    #Set the monitor collection to empty and create the collection to contain monitors
    $MonitorColl = @()
    $MonitorColl = New-Object "System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]"

    #Get specific monitors matching a displayname for this instance of URLtest ONLY
    #$Monitor = Get-SCOMMonitor -Instance $object -Recurse| where {$_.DisplayName -eq "Computer Not Reachable"} 
    
    #Add this monitor to a collection
    $MonitorColl.Add($Monitor)

    #Get the state associated with this specific monitor
    $State=$object.getmonitoringstates($MonitorColl)

if ($state.HealthState -eq 'Error') {  
$Props=@{}
$Props.ServerName=$Object.DisplayName
$Props.Reachable=$state.HealthState
New-Object -TypeName PSCustomObject -Property $props | Write-Output 
}
}

Recoveries

Lists recoveries in specified management pack with the class displayNames targed. USeful in finding out custom recoveries created.

Get-SCOMManagementPack -Name myMPName  | Get-SCOMRecovery | Select-Object -Property DisplayName,@{Name="Target";Expression={(get-scomclass -Name $_.Target.Identifier.Path).DisplayName}},Enabled