DPM Commands in Powershell Version 2

I am running a PowerShell script that requires a connection to the DPM server.

When I run the cmdlet Connect-DPMServer <DPM Server Name>

from the DPM command line, the command succeeds and I can connect to the server.

However, when I wrap the same command in a script and call the script through DPM Management Console, 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

      

Likewise with other DPM cmdlets such as Get-DPMProtectionGroup

.

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

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

Edit

There are some observations I have made. My script has two parts, a shell script and a helper script that is called by the shell script as an independent job.

All DPM commands are identified in the shell script, but they are not identified in the helper script when it is run as a job.

Any explanation why this might be and any suggestions for fixing it?

+3


source to share


1 answer


I figured out the solution and here it is:

What Happens The wrapper script is executed in DPM PowerShell and then invokes the helper script as a separate job or thread. The environment this helper script runs in is the native Windows shell, not DPM Powershell. Therefore, DPM commands are not identified there.



Solution Individual DPMs need to be imported immediately after calling the helper script. These steps are as follows:

  • Right-click the DPM Management Shell icon and view the properties.
  • Select the Target value. To me it looks likeC:\Windows\system32\windowspowershell\v1.0\powershell.exe -noexit -File "D:\DPM\DPM\bin\dpmcliinitscript.ps1"

  • A parameter value -File

    that "D:\DPM\DPM\bin\dpmcliinitscript.ps1"

    is a file that, when imported into Windows Powershell, converts it to DPM Management Console. This means that it loads the shell using DPM commands.
  • Include this file in a helper script via dot-sourcing. This means that the first line of the auxiliary script should look like this:."D:\DPM\DPM\bin\dpmcliinitscript.ps1"

    This will help the called wrapper identify specific DPM commands.

+1


source







All Articles