我正在运行一个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其他DPM (如Get-DPMProtectionGroup )也是如此。
我正在Windows 2008 R2上运行Powershell 2.0版本。
这种奇怪行为的原因是什么,我怎样才能避免这种情况呢?
编辑
我做了一些观察。我的脚本有两个部分:一个包装脚本和一个助手脚本,包装脚本作为一个独立的任务调用。
所有DPM命令都在包装器脚本中标识,但在作为作业运行时,助手脚本中没有标识它们。
对此有何解释和解决的建议?
发布于 2015-07-24 05:38:53
我想出了解决办法,这就是:
正在发生的事情包装器脚本在DPM PowerShell中运行,然后作为单独的作业或线程调用助手脚本。此助手脚本运行的环境是windows本机Powershell,而不是DPM。因此,DPM命令在那里没有标识。
解决方案-- DPM特定模块需要在调用助手脚本时立即导入。这些步骤如下:
C:\Windows\system32\windowspowershell\v1.0\powershell.exe -noexit -File "D:\DPM\DPM\bin\dpmcliinitscript.ps1"-File (即"D:\DPM\DPM\bin\dpmcliinitscript.ps1" )的值是导入到Windows时将其转换为的文件。这意味着,它使用DPM命令加载shell。."D:\DPM\DPM\bin\dpmcliinitscript.ps1"
这将帮助被调用的shell识别特定于DPM的命令。https://stackoverflow.com/questions/31578658
复制相似问题