Page 1 of 1

Get-WmiObject : Out of memory error?

Posted: Tue Jan 22, 2019 4:23 am
by ITEngineer
Hi All,

I am trying to learn to script with WMI object & PowerShell, so I'm not sure why the simple script below does not work for the some server, but work for the other?

Code: Select all

$Server = 'PRDSQL17-VM'

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
The result is:

Code: Select all

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
Any help would be appreciated.

Thanks.

Re: Get-WmiObject : Out of memory error?

Posted: Tue Jan 22, 2019 4:49 am
by jvierra
It appears that you have WMI issues. The scripts are correct.

Re: Get-WmiObject : Out of memory error?

Posted: Tue Jan 22, 2019 5:10 am
by ITEngineer
jvierra wrote:
Tue Jan 22, 2019 4:49 am
It appears that you have WMI issues. The scripts are correct.
So how to fix that issue or change it into Get-Service instead?

Re: Get-WmiObject : Out of memory error?

Posted: Tue Jan 22, 2019 9:36 am
by jvierra
The first thig to do is to reboot the problem server and test again.

Get-Service uses WMI so it may also fail.

Re: Get-WmiObject : Out of memory error?

Posted: Tue Jan 22, 2019 5:21 pm
by ITEngineer
jvierra wrote:
Tue Jan 22, 2019 9:36 am
The first thig to do is to reboot the problem server and test again.

Get-Service uses WMI so it may also fail.
I can't reboot it now since it is Critical production server. Is there any service that I can restart?

What about using the Get-CimInstance?