Export management pack XML from SquaredUp PowerShell tile

Have anyone been able to export a management pack from within a PowerShell tile using the Export-SCOMManagementPack?
The purpose of this is to parse the MP XML, to present the dynamic membership rules for the groups in the MP on a dashboard.

When running Export-SCOMManagementPack from the PowerShell tile, I get the error: “The user DOMAIN\SQUAREDUPSERVER$ does not have sufficient permission to perform the operation.”

(Get-SCOMManagementPack has the -Credential parameter, but Export-SCOMManagemnetPack does not)

I tried to use Invoke-Command, and execute the script on a management server:

$resultString=Invoke-Command -Credential $Credentials -ComputerName “MS01”-ScriptBlock {
$ManagementPack = Get-SCOMManagementPack -DisplayName “MPName”
$ManagementPack | Export-SCOMManagementPack -Path “C:\Windows\Temp”
$content = Get-Content -Path “C:\Windows\Temp$($ManagementPack.Identifier.Path).xml”
Remove-Item “C:\Windows\Temp$($ManagementPack.Identifier.Path).xml”
$content #return it

This does work - but for some reason the Invoke-Command is extremely slow at returning the content. It takes around 3 minutes to return the XML for a MP that is around 1.3 MB. And the servers are just next to each other.

Right now I’ve settled on a solution where I from a scheduled task export all management packs to the SquaredUp server, and then read the XML file directly instead. But if it I could get the content directly, it would be a better/simpler solution.

I already engaged SquaredUp support on this, and after some great troubleshooting steps (unfortunately without any success), the supporter suggested that I posted my question in here.

Hi Kenneth,

Get-Content has some known issues with larger files:

The TLDR is that it does a bunch of parsing on the input before making it available to you, which is heavier weight than it could/should be.

If you are allowed to dip into .NET (sometimes security policies prevent this) the suggestion on that issue is to use File.ReadAllLines Method (System.IO) | Microsoft Learn
Which will give you an array of strings. But depending on what you want/need there are a variety of solutions/workarounds listed in that issue.


Hi Kenneth

As you’ve already worked out. This is happening because the application pool account SquaredUp uses doesn’t have permissions to export management packs. You could get around this by creating a new PowerShell profile in SquaredUp and assigning a user with the correct permissions. Export-SCOMManagementPack requires a user that is a member of the ‘Operations Manager Administrators’ role.

This feels like far too much permission to me. It might be better to access the MP elements directly rather than exporting to XML first. You could do something like…

$Group = Get-SCOMGroup -Id '6f7e3306-beeb-2996-3795-7c1eafb925b8' # 'All Windows Computers'
$DiscoveryXML = [XML]($Group.GetMonitoringDiscoveries().createnavigator() | Select -ExpandProperty outerxml)

To access the membership rules as XML. You should then be able to use the same code to parse the XML as you are already using and the profile user would only need to be a member of ‘Operations Manager Advanced Operators’

Hope that helps

Thank you Keith!
I was looking for a way to get the discovery XML directly from SCOM, but was not able to do so, which lead me down the path of importing the XML file instead. But with your lines of code, I just what I initially wanted - thanks! It’s also a way better solution than exporting/reading XML files.

1 Like

Hi Evil Penguin
Thanks for your answer :slight_smile: From what I could see in my tests, it was not the Get-Content that was the issue (the file is only 1.3 mb in size), but when the content should be serialized back to the SquaredUp server initially invoking the script lines.
However, I found another solution, so I’ll stick with that instead. But thanks for your help and time!