Wednesday, March 23, 2016

SCOM: Compare MP's between Management Groups with PowerShell

A short blog post about comparing management packs between SCOM environments I know there are tools available to compare management packs, but that's no fun. Creating this compare script with PowerShell to accomplish the same didn't cost me that much time. And of course, doing it yourself with PowerShell is just more fun. So here it is.

This script gives you a gridview with the differences, as well as an CSV output file.
#Compares unsealed/sealed MP's between two management groups
#Author: Michiel Wouters
#Date: 23-03-2016

[CmdletBinding()]
Param(
   [Parameter(Mandatory=$False)]
   [string]$ms1="server1", # A management server of the source environment, default value
   
   [Parameter(Mandatory=$False)]
   [string]$ms2="server2", # A management server of the target environment, default value

   [Parameter(Mandatory=$False)]
   [boolean]$Sealed=$True
  
)

New-SCOMManagementGroupConnection -ComputerName $ms1
$mmgtgrpconn1 = Get-SCOMManagementGroupConnection -ComputerName $ms1

New-SCOMManagementGroupConnection -ComputerName $ms2
$mmgtgrpconn2 = Get-SCOMManagementGroupConnection -ComputerName $ms2

Set-SCOMManagementGroupConnection -Connection $mmgtgrpconn1
$mgmtgrp1mps = Get-SCOMManagementPack | ? {$_.Sealed -eq $Sealed} | Select DisplayName, Name, Version | Sort DisplayName

Set-SCOMManagementGroupConnection -Connection $mmgtgrpconn2
$mgmtgrp2mps = Get-SCOMManagementPack | ? {$_.Sealed -eq $Sealed} | Select DisplayName, Name, Version | Sort DisplayName


#set SynWindow for compare object
if($mgmtgrp2mps.Count -gt $mgmtgrp1mps.count) { 
    $SyncWindow = [math]::Ceiling($mgmtgrp2mps.Count/2)
}  else { 
    $SyncWindow = [math]::Ceiling($mgmtgrp1mps.Count/2)
}

$comparison = Compare-Object -ReferenceObject $mgmtgrp1mps -DifferenceObject $mgmtgrp2mps -Property DisplayName, Name, Version -SyncWindow $SyncWindow | Sort DisplayName
#output to screen
$comparison | Out-GridView
#output to csv file
$comparison | Export-CSV -Path .\SCOM_MPDiff_$(Get-Date -Format "yyyyMMdd_HHmm").csv -NoTypeInformation -Delimiter ";"

Screenshots:



0 reacties:

Post a Comment