PowerShell Get-WmiObject:内存不足错误?

时间:2019-01-22 11:28:32

标签: powershell scripting active-directory wmi wmi-query

人们

我正在尝试学习使用WMI对象和PowerShell编写脚本,因此我不确定为什么下面的简单脚本不适用于某些服务器,而适用于其他服务器?

$Server = 'PRODDB17-V'

Get-WmiObject -ComputerName $Server -Class Win32_LogicalDisk -Filter "DriveType = 3" | ft -AutoSize
Get-WmiObject -Query "SELECT * FROM Win32_Service WHERE DisplayName LIKE '%SQL%'" -ErrorAction Stop -ComputerName $Server | ft -AutoSize

我收到如下错误:

DeviceID DriveType ProviderName    FreeSpace          Size VolumeName
-------- --------- ------------    ---------          ---- ----------
C:               3               50624507904  104751689728 SYSTEM    
D:               3              135013552128 1915396026368 DATA      
L:               3               71224967168  167772155904 LOGS      
S:               3              131093495808 2198886936576 SQL       
P:               3              107122515968  644108775424 PageFile 
T:               3                8489771008   42946523136 TEMPDB    


Get-WmiObject : Out of memory 
At line:5 char:1
+ Get-WmiObject -Query "SELECT * FROM Win32_Service WHERE DisplayName LIKE '%SQL%' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

1 个答案:

答案 0 :(得分:0)

默认情况下,将为powershell分配150 MB的内存,这可能会导致某些命令失败。

使用以下命令来增加限制(从提升的PS实例运行)并重新启动“ Windows Management Instrumentation”服务。

set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512

根据您的物理内存增加限制。