Preface
At our company we are in the need of creating Management Packs including a Group using discovered Properties. Therefore we have a class Windows.Computer.Extended and an attribute called ServerRole, of course the Base Class is Windows Computer.
So, the first thing we had to figure out was how to get the environment of the Operations Manager Console as well as the assemblies into a standalone Script.
Loading the OpsMgr Snapin
As you can see in the code below, we check at first if the Snapin is already loaded, if it's not, we load it.
# Check if the OpsMgr.Client PSSnapin is already loaded, if not, load it.
if ((Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.EnterpriseManagement.OperationsManager.Client'}) -eq $null)
{
Write-Host("Loading Operations Manager Client PS Snapin")
Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client # <- that's the magical line
}
else
{
Write-Host("Operations Manager Client PS Snapin is already loaded")
}
Loading the Assemblies
Additionally we need to load the Assemblies using the PartialName. However, make sure first that these assemblies are available on the client by checking the folder: %windir%\assembly
You should have these Assemblies in there: Microsoft.EnterpriseManagement.OperationsManager and Microsoft.EnterpriseManagement.OperationsManager.Common
Once verified, all you need are the lines below:
# Load the Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.OperationsManager")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.OperationsManager.Common")
Setting the Location and loading the ManagementGroup
# Set Location to the RMS. Afterwards you can use any Powershell Console like the Operations Manager Console. And of course, you can use this in Powershell Modules
$rms = "localhost" # Insert the FQDN of your RMS here
Write-Host("Setting Location $rms.")
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
$MG = New-ManagementGroupConnection -ConnectionString:$rms -ErrorVariable errSnapin;
Set-Location $rms -ErrorVariable errSnapin;
Aucun commentaire:
Enregistrer un commentaire