在 Start-Job 脚本块内时,远程 Get-WmiObject 调用失败
好吧,我试图解决这个问题,但我想是时候去网上问问了。我想知道这是一个错误还是什么。
我正在尝试针对多台计算机启动作业,以确定哪些数据库名称驻留在它们上。
我的 Computer1 系统设置是: Powershell 2.0、Windows 2k3 Enterprise x64
在 Computer1 上我可以运行:
Start-Job -scriptblock {gwmi -query "select * from win32_computersystem" -ComputerName "Computer2"}
并且该作业将永远陷入“正在运行”状态。但如果我在 shell 中的作业脚本块之外运行相同的命令,则不会。
我已经尝试过这个确切的设置 这里使用本地管理员(相对于我的域)的凭据,但结果相同。由于某种原因它对我不起作用。
我尝试构建一个不使用 gwmi 的自定义 WMI dotnet 对象,但我得到了相同的结果!
-asjob参数?: 这不是一个解决方案。
使用此参数时,在 12GB 系统上使用大约 2GB 内存时,powershell 窗口会崩溃;而我可以毫无问题地使用 start-job 一直到 12GB。我不妨以串行方式运行每个查询。
此外,在 Gwmi 上使用 -Asjob 参数时永远不会回收内存,因此无法继续执行其他作业;即使在运行“remove-job * -force”或“[GC]::Collect()”之后,powershell.exe 的内存消耗也顽固地保持不变(再次与 start-job 不同)。
由于 SQL 实例名称不同,因此 wmi 类名称也不同。所以我需要针对多个类运行多个查询命令。虽然在技术上可行,但它更复杂,并且考虑到上述内存要求,限制为 2GB。我希望有人知道如何让 start-job 正常工作。
所以我唯一没有尝试过的是也许我必须指定权限参数?
Alright, I've tried to figure this out, but figured it's time to ask the interwebs. I'm wondering if this is a bug or what.
I'm trying to start jobs against multiple computers to determine which database names reside on them.
My Computer1 system setup is: Powershell 2.0, Windows 2k3 Enterprise x64
On Computer1 I can run:
Start-Job -scriptblock {gwmi -query "select * from win32_computersystem" -ComputerName "Computer2"}
And the job will be stuck in a state of "Running" forever. But not if I run the same command outside the job's script block in the shell.
I've tried this exact setup here with a local admin's (vs my domain) credentials, but same result. It doesn't work for me for some reason.
I've tried building a custom WMI dotnet object that doesn't use gwmi, but I get the same result!
The -asjob parameter?:
This is not a solution.
When using this parameter, the powershell window crashes at around 2GB memory used on a 12GB system; Whereas I can use start-job all the way to 12GB without problems. I might as well run every query in serial fashion.
Also, memory is never reclaimed when using the -Asjob parameter on Gwmi, so no further jobs can continue; even after running "remove-job * -force" or "[GC]::Collect()", the memory consumption for powershell.exe stubbornly remains the same (again, unlike start-job).
Since SQL instance names vary, the wmi class names vary. So I need to run multiple query commands against multiple classes. While is technically doable, its more complex and, given the above memory requirements, limited to 2gb. I'm hoping someone will just know how to make start-job work like it should.
So about the only thing I haven't tried is maybe I have to specify the authority parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用 Invoke-Command -asJob 来实现此目的:
您可以用计算机列表替换计算机名称。不要尝试在脚本块中使用的 CmdLets 中再次编码 '-Computername。
(已编辑)
我尝试使用命令行,它对我从客户端 Windows 7(64 位)到 W2K3(32 位)都有效。
我的客户端不在服务器的域中,我使用域管理员凭据。
您是否在 32 位 Powershell 或 64 位 Powershell 中进行了测试?
您是否尝试停止远程计算机上的 WMI 服务并清理 WMI 数据库,当您在 WMI 服务器上进行过多测试(例如使用事件)时,它有时是合适的。
I use Invoke-Command -asJob for this :
You can replace the machine name by a list of machines. Don't try to code again '-Computername in the CmdLets you are using in the script block.
(Edited)
I try you command line and it works for me from a client Windows Seven (64 Bits) to a W2K3 (32 bits)
My client is NOT in the domain of the server and I use domain admin credentials.
Have you made the test from a 32Bit Powershell or a 64 Bits Powershell ?
Do you try to stop WMI service on remote machine and clean the WMI database, it's sometime suitable when you made too much tests on a WMI server (with events for example).