locked
Use Get-WmiObject with PCs on domain RRS feed

  • Question

  • Hi,

    Apologies, I'm new to PowerShell so be gentle.  Please let me know if I need to provide any more information.

    I'm trying to make a script to get the list of computer names on a domain and check whether their drives are being reported as failure predicted.  

    I'm using Get-ADComputer to get the names all PCs which have the format PC401*, this seems to work.  I then use a ForEach loop to Get-WmiObject to get the data I need.  I think the problem is with the format of the output of the Get-ADComputer, but I can't find a way to format it that the Get-WmiObject likes.  If I specify a PC name in the Get-WmiObject query it outputs correctly, but when I use the $computer variable it gives a RPC connection error (presumably because the PC name is formatted wrongly).  Any thoughts on how I can achieve this would be appreciated. 

    Import-Module ActiveDirectory
    $computerslist = Get-ADComputer -Filter {name -like PC401*}| Select-Object -Property Name
    
    ForEach ($computer in $computerslist) {
    Get-WmiObject -namespace root\wmi -class MSStorageDriver_FailurePredictStatus -ComputerName $computer | 
    Select PSComputerName, InstanceName, PredictFailure, Reason}

    Wednesday, July 12, 2017 9:24 AM

Answers

  • This is how PowerShell does this:

    Get-ADComputer -Filter "name -like 'PC401*'" |
    	ForEach-Object{
    		Get-WmiObject Win32_BIOS -ComputerName $_.Name 
    	} |
    	Select Name, SerialNumber, Version
    
    The "MSStorageDriver_FailurePredictStatus"  will not be available on most systems.


    \_(ツ)_/

    • Marked as answer by Leo G-B Wednesday, July 12, 2017 10:04 AM
    Wednesday, July 12, 2017 9:51 AM

All replies

  • This is how PowerShell does this:

    Get-ADComputer -Filter "name -like 'PC401*'" |
    	ForEach-Object{
    		Get-WmiObject Win32_BIOS -ComputerName $_.Name 
    	} |
    	Select Name, SerialNumber, Version
    
    The "MSStorageDriver_FailurePredictStatus"  will not be available on most systems.


    \_(ツ)_/

    • Marked as answer by Leo G-B Wednesday, July 12, 2017 10:04 AM
    Wednesday, July 12, 2017 9:51 AM
  • Perfect! Using the ForEach-Object worked.  I'm confused as to why that's doing anything different to mine, but it's working so I'll take it.  Thanks very much!
    Wednesday, July 12, 2017 10:06 AM
  • To me ForEach is messy.

    Get-WMIObject -ComputerName (Get-ADComputer -Filter *).Name Win32_BIOS -ErrorAction SilentlyContinue | Select Name, SerialNumber, Version


    Thursday, April 11, 2019 11:31 PM