Get-WmiObject : Out of memory error?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 148
Joined: Wed Oct 12, 2011 10:52 am

Get-WmiObject : Out of memory error?

Post by ITEngineer » Tue Jan 22, 2019 4:23 am

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.
/* IT Engineer */

User avatar
jvierra
Posts: 13802
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-WmiObject : Out of memory error?

Post by jvierra » Tue Jan 22, 2019 4:49 am

It appears that you have WMI issues. The scripts are correct.

User avatar
ITEngineer
Posts: 148
Joined: Wed Oct 12, 2011 10:52 am

Re: Get-WmiObject : Out of memory error?

Post by ITEngineer » Tue Jan 22, 2019 5:10 am

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?
/* IT Engineer */

User avatar
jvierra
Posts: 13802
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Get-WmiObject : Out of memory error?

Post by jvierra » 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.

User avatar
ITEngineer
Posts: 148
Joined: Wed Oct 12, 2011 10:52 am

Re: Get-WmiObject : Out of memory error?

Post by ITEngineer » Tue Jan 22, 2019 5:21 pm

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?
/* IT Engineer */

Locked