DPM Commands in Powershell Version 2

1.7k views Asked by At

I am running a PowerShell script which requires connection to a DPM Server.

When I run run the Connect-DPMServer <DPM Server Name> cmdlet from the DPM Manangement Shell, the command succeeds and I am able to connect to the server.

However, when I enclose the same command in a script and invoke the script through the DPM Management Shell, the following error occurs:

The term 'Connect-DPMServer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo          : ObjectNotFound: (Connect-DPMServer:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Similar is the case with other DPM cmdlets like Get-DPMProtectionGroup.

I am running Powershell version 2.0 on Windows Server 2008 R2.

What is the reason for this peculiar behaviour and how can I get around this?

Edit

There is some observation I made. My script has two parts: A wrapper script and a helper script which is called by the wrapper script as an independent job.

All the DPM Commands are identified in the wrapper script but they are not identified in the helper script when it runs as a job.

Any explanation why this may be and any suggestions to resolve the same?

1

There are 1 answers

0
M_coder On BEST ANSWER

I figured out the solution and here it is:

What is Happening The wrapper script runs in the DPM PowerShell and then invokes a helper script as a separate job or thread. The environment in which this helper script runs is windows native powershell and not DPM Powershell. Hence the DPM commands are not identified there.

Solution The DPM specific modules need to be imported as soon as the helper script is invoked. The steps are as follows :

  1. Right Click on the DPM Management Shell icon and view properties.

  2. Select the value of Target. For me, it looks like this C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noexit -File "D:\DPM\DPM\bin\dpmcliinitscript.ps1"

  3. The value of the parameter -File that is "D:\DPM\DPM\bin\dpmcliinitscript.ps1" is the file which when imported to Windows Powershell converts it to DPM Management Console. That means, it loads the shell with DPM commands.

  4. Include this file in the helper script through dot-sourcing. Which means, the first line of the helper script should look like this : ."D:\DPM\DPM\bin\dpmcliinitscript.ps1"

    This will help the invoked shell to identify the DPM specific commands.