SCOM 上的 PowerShell 无法导入模块
我有一个问题,如果没有帮助,我无法解决) 我在第一台 PC 上有 SCOM,在第二台 PC 上有 SCOM 代理。当我的类在代理 PC 中发现时,它必须运行 PowerShell 脚本。此脚本包含命令:
Import-Module FailoverClusters
,但此命令失败并出现异常:
加载扩展类型数据文件时发生以下错误: Microsoft.PowerShell,C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ Modules \ FailoverClusters \ FailoverClusters.Types.ps1xml:文件被跳过,因为它已经存在于“Microsoft.PowerShell”中。
我不知道该怎么办。
I have a problem I cannot solve without help )
I have SCOM in first PC, and I have SCOM agent in second. When my class discoveries in agent PC, it must run PowerShell script. This script contains command:
Import-Module FailoverClusters
but this command fails with exception:
The following error occurred while loading the extended type data file:
Microsoft.PowerShell, C:\Windows\system32\WindowsPowerShell\v1.0\Modules\FailoverClusters\FailoverClusters.Types.ps1xml : File skipped because it was already present from "Microsoft.PowerShell".
I dont know what to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如这篇博文< /a> 指出,加载模块时可以忽略扩展类型数据错误。它告诉您该类型已经加载并且无法再次加载。
As this blog post points out, you can ignore extended type data errors when loading modules. It's telling you that the type is already loaded and it can't load it a second time.
解决方法:
我发现使用 SCOM 2007 R2(尚未在 SCOM 2012 上测试过),powershell 无法导入 FailoverClusters 模块。我尝试了跳过错误的建议。代理第一次执行脚本时会跳过。此后,该脚本的后续执行将无法使 Get-Cluster cmdlet 可用。每当您重新启动代理时,它都会跳过错误并且 cmdlet 可用,但后续执行再次无法加载 cmdlet。
提升权限和不受限制的脚本执行并不能解决这个问题。
定期重新启动代理就是这样一个大锤。我没有接受它。
但是我确实发现,如果我使用一个轻量级脚本来生成一个新的 powershell 实例并执行我的主代码(保存在磁盘上的文件或动态生成磁盘上的脚本),则新的 powershell 实例每次都会成功加载模块并且该 cmdlet 始终可用。
我知道有人担心从另一个实例生成一个实例(例如 vbscript 生成 powershell)会存在性能问题。但就我而言,我能够让代理调用我的 powershell 包装器,动态生成 500 行脚本(使用 Streamwriter 进行性能),然后以包装器形式在新的 powershell 中生成它。这一切都在大约 6 秒内执行,其中包括查询 Get-ClusterResources。
我猜这是 SCOM 代理中的一个错误......
WORKAROUND:
I found that with SCOM 2007 R2 (haven't tested this on SCOM 2012), powershell fails to import FailoverClusters module. I tried the suggestion to skip the error. Skipping works the very first time the agent executes the script. After that, subsequent executions of the script fail to have the Get-Cluster cmdlet available. Whenever you restart the agent, it skips the error and the cmdlet is available, but again subsequent executions fail to load the cmdlet.
Elevated permissions and unrestricted script execution didn't help the issue.
Restarting the agent regularly is such a sledge hammer. I did not entertain it.
However I did find that if I used a light-weight script that spawns a new powershell instance and executes my main code (file saved on disk or generate the script on disk on the fly), the fresh powershell instance loaded the module successfully every time and the cmdlet was always available.
I know there are concerns that spawning one instance from another (like vbscript spawing powershell) has perf issues. But in my case, I was able to have the agent call my powershell wrapper, generate a 500 line script on the fly (using streamwriter for perf), and then spawn it in a fresh powershell form the wrapper. It all executed in about 6 seconds, which included querying Get-ClusterResources.
I'm guessing this is a bug in the SCOM agent...
Powershell脚本(GPO_Discovery.ps1)调用WriteErrorLine方法输出以下数据:
可以看出,我在尝试运行时遇到了同样的问题:
所以我尝试了:
这些都没有帮助。我准备尝试完全删除 Import CMD-Let,然后重试。如果这对我有用,我会发布。
Powershell Script (GPO_Discovery.ps1) called WriteErrorLine method to output the following data:
As it can be seen, I have the same problem on trying to run :
So I tried:
Neither of these have helped. I am about to attempt to remove the Import CMD-Let completely and try again. I will post if that works for me.