Using the "-WhatIf" parameter with the Import-SCManagementPack cmdlet

Using the "-WhatIf" parameter with the Import-SCManagementPack cmdlet

In short... don't do this.

PS> Import-SCManagementPack -Fullname "\\networkshare\managementpack.mpb" -WhatIf


If you run Get-Help Import SCManagementPack -Detailed, and scroll down toward the bottom a bit, you'll see the description for this parameter:

"-WhatIf [<SwitchParameter>]
      Describes what would happen if you executed the command without actually executing the command."

Oops! Somebody got that one wrong. Go ahead and try it. Then go ahead and run the Get-SCManagementPack cmdlet

PS> Get-SCManagementPack -DisplayName "managementpack"

That's right! The management pack was installed. On this cmdlet, using Service Manager 2012 R2, the WhatIf paramerter will not prevent execution of the command as it is suppose to.

Realistically, in this situation, there's likely no harm done. The Management Pack, which at some point, you planned to Import, has been imported. If you were using this to ensure you typed the file path correctly, try using Test-Path instead.

PS> $ManagementPack = "\\networkshare\managementpack.mpb"
PS> If (Test-Path ("$ManagementPack"))
           {Import-SCManagementPack "$ManagementPack"}



Bulk Import of Service Manager Management Packs

Yes. It's a bit more typing, but how many Management Packs do you plan on importing? More than one? Try wrapping this in a ForEach loop. You can find all of the *.MPB files located in a specific directory, then import each one.

PS> $BasePath = "\\networkshare\"
PS> $MPList = Get-ChildItem $BasePath -Recurse -Name "*mpb"

PS> foreach ($MP in $MPList) {
PS> $ManagementPack = $BasePath + $MP
PS> If (Test-Path ("$ManagementPack"))
           {Import-SCManagementPack "$ManagementPack"}
}

Replace the $BasePath with the location where your MP's are located. Ensure the last backslash is included in this string.

This script will search for any MPB files located in the specified directory and sub-directories, then import them in to SCSM.

Please be aware, this script will not look for any dependencies. If you have a specific order in which certain management packs should be applied, you will want to deal with those outside of this script.

And there you have it! How to turn a one sentence post warning about a non-functional -WhatIf parameter in to a full page post.

Please let me know if you found this information helpful, if you find any inaccuracies or have questions.

RingCentral for Google, Zendesk, Salesforce and more. 30-Day Free Trial!







No comments :

Post a Comment