Export all unsealed management packs

February 8, 2011 Posted by Anders Asp

Here’s a little powershell script that I use for exporting all unsealed MPs. It’s really useful to run once in a while so you have a backup of all unsealed MPs.

The script will create a new folder with the current date and store all MPs in that folder. Change the $OutPutDir variable to a folder of your choice.

Add-PSSnapin SMCMDLetSnapIn

$OutPutDir = "C:\Unsealed MPs\"

$UnsealedMPs = Get-SCSMManagementPack | ?{ ! $_.Sealed }

$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToShortDateString()
$CompletePath = ($OutPutDir + $CurrentDate)

if ( ! (test-path  $CompletePath))
{
    $output = New-Item -Type Directory -Name $CurrentDate -Path $OutPutDir
}

$UnsealedMPs | %{
    "   Exporting: {0}" -f $_.Name 
    $_ | Export-SCSMManagementPack -directory "$CompletePath"
    }

5 Responses to Export all unsealed management packs

  1. Ozge says:

    When I run the script at PowerShell window, I get the following errors for each MP:

    Exporting: ServiceManager.Dashboards
    Export-SCManagementPack : A parameter cannot be found that matches parameter name ‘directory’.
    At line:3 char:46
    + $_ | Export-SCSMManagementPack -directory <<<< "$CompletePath"
    + CategoryInfo : InvalidArgument: (:) [Export-SCManagementPack], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,SMLets.ExportManagementPackCommand

  2. Zhenya Ieropolskiy says:

    Hi, help me, please
    my script:

    Import-Module smlets
    $OutPutDir = “C:\Export Management Pack”
    $CurrentDate = Get-Date
    $CurrentDate = $CurrentDate.ToShortDateString()
    $CompletePath = ($OutPutDir + $CurrentDate)
    if ( ! (test-path $CompletePath)){$output = New-Item -Type Directory -Name $CurrentDate -Path $OutPutDir}
    Get-SCSMManagementPack | where{$_.sealed -eq $False} | Export-SCSMManagementPack -Path $output

    same error on-path (((

  3. SirLearnAlot says:

    This probably wont help the users above me… but the correct command is -TargetDirectory

    The way I found this out (to aid you in solving similar future errors) was by typing get-help on the export-scsmmanagementpack and reviewing available options.

    If anyone is interested I am opening a website soon and its going to contain alot of SCSM tips, email me at srlearnalot@gmail.com

    Cheers 🙂

  4. Jesse Harris says:

    Edited slightly so this can be used to backup multiple SCSM deployments to a single file share.

    $MG = Get-ScManagementGroupConnection
    $MG.ManagementGroupName
     

    $OutPutDir = “\\\\” + $MG.ManagementGroupName
     
    $UnsealedMPs = Get-SCSMManagementPack | ?{ ! $_.Sealed }
     
    $CurrentDate = Get-Date
    $CurrentDate = $CurrentDate.ToShortDateString()
    $CompletePath = ($OutPutDir + “\” + $CurrentDate)
     
    if ( ! (test-path  $CompletePath))
    {
        $output = New-Item -Type Directory -Name $CurrentDate -Path $OutPutDir
    }
     
    $UnsealedMPs | %{
        ”   Exporting: {0}” -f $_.Name
        $_ | Export-SCSMManagementPack -path “$CompletePath”
        }

Leave a Reply

Your email address will not be published. Required fields are marked *

*