Ask your 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.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Tue Jan 22, 2019 3: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 */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Tue Jan 22, 2019 3:49 am
It appears that you have WMI issues. The scripts are correct.
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Tue Jan 22, 2019 4:10 am
jvierra wrote: ↑ Tue Jan 22, 2019 3: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 */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times
Post
by jvierra » Tue Jan 22, 2019 8: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.
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times
Post
by ITEngineer » Tue Jan 22, 2019 4:21 pm
jvierra wrote: ↑ Tue Jan 22, 2019 8: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 */
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked