For the most part, running scripts through the DPM Management Shell works for most people. However, if you have many people that may be using your DPM oriented scripts (any script calling a DPM specific commandlet), it may be less confusing for them to run those through the actual powershell console. Also, this allows you to easily run DPM scripts as a scheduled task as it will invoke the standard powershell console and simply load the needed snapin in your script. Please keep in mind these two things:
Once these pre-requisites have been met, you simply need to put the following in your DPM script (after any input parameters) to run your DPM scripts in the standard powershell console:
1 2 3 4 5 | if (!(Get-PSSnapin microsoft.dataprotectionmanager.powershell)) { write-host "Adding PS Snapin for DPM..." -Fore Green add-PSSnapin Microsoft.DataProtectionManager.PowerShell } |
This will look on the local machine to see if the DPM snapin is loaded, and if not, load it. You can verify that the snapin has been loaded (or not loaded), by doing the following:
Not loaded:
1 | Get-PSSnapin microsoft.dataprotectionmanager.powershell |
Get-PSSnapin : No Windows PowerShell snap-in matches criteria microsoft.dataprotectionmanager.powershell. At line:1 char:13 + Get-PSSnapin <<<< microsoft.dataprotectionmanager.powershell
Loaded:
1 | Get-PSSnapin microsoft.dataprotectionmanager.powershell |
Name : Microsoft.DataProtectionManager.PowerShell PSVersion : 1.0 Description : This is a DPM Powershell snapin.
Tags: DPM, powershell