3

我正在运行一个需要连接到 DPM 服务器的 PowerShell 脚本。

当我从 DPM Manangement Shell 运行Connect-DPMServer <DPM Server Name>cmdlet 时,命令成功并且我能够连接到服务器。

但是,当我在脚本中包含相同的命令并通过 DPM 命令行管理程序调用脚本时,会出现以下错误:

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

其他 DPM cmdlet(如Get-DPMProtectionGroup.

我在 Windows Server 2008 R2 上运行 Powershell 2.0 版。

这种特殊行为的原因是什么,我该如何解决?

编辑

我做了一些观察。我的脚本有两部分:一个包装器脚本和一个由包装器脚本作为独立作业调用的帮助器脚本。

所有 DPM 命令都在包装脚本中标识,但当它作为作业运行时,它们不会在帮助脚本中标识。

任何解释为什么会这样以及解决相同问题的任何建议?

4

1 回答 1

1

我想出了解决方案,这里是:

发生了什么 包装脚本在 DPM PowerShell 中运行,然后将帮助程序脚本作为单独的作业或线程调用。此帮助程序脚本运行的环境是 Windows 本机 Powershell,而不是 DPM Powershell。因此,那里没有识别 DPM 命令。

解决方案 调用帮助程序脚本后,需要立即导入 DPM 特定模块。步骤如下:

  1. 右键单击 DPM 命令行管理程序图标并查看属性。

  2. 选择目标值。对我来说,它看起来像这样C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noexit -File "D:\DPM\DPM\bin\dpmcliinitscript.ps1"

  3. 参数的值-File"D:\DPM\DPM\bin\dpmcliinitscript.ps1"导入到 Windows Powershell 时将其转换为 DPM 管理控制台的文件。这意味着,它使用 DPM 命令加载 shell。

  4. 通过点源将此文件包含在帮助程序脚本中。这意味着,帮助脚本的第一行应该是这样的:."D:\DPM\DPM\bin\dpmcliinitscript.ps1"

    这将帮助被调用的 shell 识别 DPM 特定的命令。

于 2015-07-24T05:38:53.337 回答