Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5100 -Message "Determined that the Pack Name would be $MPID for $SolutionName" -Category 50
#Create Store and Pack
$MPStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore
$MP = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($MPID, $MPName, (New-Object Version(1, 0, 0)), $MPStore)
$FoundMP = $null
Try
{
#Before we go further, check for Installed Pack
$FoundMP = $MG.GetManagementPacks($MPID)
$PackInstallDate = $FoundMP.TimeCreated.ToLocalTime().ToString()
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5150 -Message "We found the pack $MPID for $SolutionName, it was installed on $PackInstallDate" -Category 50
}
Catch
{
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5151 -Message "We did not find the pack $MPID for $SolutionName, Time to make it" -Category 50
}
If ($FoundMP -eq $null)
{
#time to get to work
#Modify Then Import the MP
$MP.DisplayName = $MPName
$MP.Description = "Auto Generated Management Pack! This pack contains groups and overrides that allow for more granular control of OMS Solutions"
$MP.AcceptChanges()
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5210 -Message "$MPID Created, Adding to the ManagementGroup" -Category 50
$MG.ImportManagementPack($MP)
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5220 -Message "$MPID Added to the ManagementGroup, Sleeping for a minute and then, atempting to retrive the Live Object" -Category 50
sleep -Seconds 60
#Reconnecting as sometimes it doesn't find out pack.
$MG = New-Object Microsoft.EnterpriseManagement.ManagementGroup('localhost')
$MP = $MG.GetManagementPacks($MPID)[0]
$ReturnedMPName = $MP.DisplayName
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5221 -Message "Done Naping for $MPID, the Display name of the Returned MP was $ReturnedMPName" -Category 50
$windowsManagementPack = $mg.GetManagementPack([Microsoft.EnterpriseManagement.Configuration.SystemManagementPack]::Windows)
$instanceGroupManagementPack = $mg.GetManagementPack([Microsoft.EnterpriseManagement.Configuration.SystemManagementPack]::Group)
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5230 -Message "We were able to get all the required resources to proceed with $MPID creation" -Category 50
If ($BoolCreateGroups)
{
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5250 -Message "Creating the Enable and Disable groups for $MPID" -Category 50
#Time to create our Stub Groups
$EnableGroupID = "EnableSolutionGroup"
$DisableGroupID = "DisableSolutionGroup"
$EnableGroupDisplayName = "$SolutionName Enable Solution workflows Group"
$DisableGroupDisplayName = "$SolutionName Disable Solution workflows Group"
MakeNewGroup $EnableGroupID $EnableGroupDisplayName
MakeNewGroup $DisableGroupID $DisableGroupDisplayName
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5250 -Message "Both the Enable and Disable groups for $MPID have been created" -Category 50
$MP.Verify()
$MP.AcceptChanges()
}
If ($BoolShouldOverride)
{
MakeAllOverrides
}
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5510 -Message "Management Pack Process is Completed for: $SolutionName" -Category 50
}
Else
{
If ($BoolShouldOverride)
{
$MP = $MG.GetManagementPacks($MPID)[0]
MakeAllOverrides
}
Write-EventLog -LogName 'OMS Admin Extensions' -Source OMSAdminSetup -EntryType Information -EventId 5501 -Message "Management Pack Process is Completed for: $SolutionName" -Category 50
}