【问题标题】:DPM Commands in Powershell Version 2Powershell 版本 2 中的 DPM 命令
【发布时间】:2015-07-23 05:13:58
【问题描述】:

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

当我从 DPM 管理外壳运行 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

Get-DPMProtectionGroup 等其他 DPM cmdlet 也是如此。

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

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

编辑

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

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

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

【问题讨论】:

  • 您可以尝试通过以下方式列出您已安装的命令:Get-command 在不工作的 shell 中
  • 我会在你的帮助脚本中打印出Get-Command 并输出带有$PSVersionTable 的Powershell 版本以缩小范围

标签: powershell dpm


【解决方案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 特定的命令。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-11
    • 2013-07-09
    • 2015-03-31
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 2017-07-10
    相关资源
    最近更新 更多