header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
get-wmiobject and for inventory
Last Post 16 Mar 2010 02:01 PM by PoSherLife. 8 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
ebrown35User is Offline
New Member
New Member
Posts:30
Avatar

--
15 Mar 2010 05:21 PM

    I am using get-wmiobject to inventory certain items in a server list stored in .csv. I need service tag, etc. This seems like it should work for just to pull the computer name and sp, but I must be missing something:

    Import-Csv C:\server_list.csv | Get-QADComputer -Identity {$_.Name} | foreach {

    $server = $_

    $server | Get-WmiObject Win32_OperatingSystem -computername $_ | select Caption,ServicePackMajorVersion | export-csv "c:\results.csv" -noType

    }

    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    16 Mar 2010 06:39 AM
    I am have tried it several different ways (using -class) and I get:

    Get-WmiObject : Invalid parameter
    At line:3 char:25
    + $server | Get-WmiObject <<<< Win32_OperatingSystem -computername $_ | select Caption,ServicePackMajorVersion | export-csv "c
    :\quiz\results\.csv" -noType
    + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand



    My eventual goal is pull

    Get-WmiObject Win32_BIOS –comp $_.Name | Select SerialNumber

    Get-WmiObject Win32_ComputerSytem –comp $_.Name | Select model,manufacturer

     
    All in the same script.

    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:352
    Avatar

    --
    16 Mar 2010 07:20 AM
    • Accepted Answer
    I'm not sure about your environment but I don't think you'll need the Get-QADComputer.  You should just be able to reference the name straight out of the csv file.  Just make sure the csv file has a column called name and that you have at least the NetBIOS name of the computer in that column. 

    If that is the case you can try this:

    $serverinfo = "" | select Caption,ServicePackMajorVersion,SerialNumber,Model,Manufacturer            
    Import-Csv .\complist.csv | %{ $winOS = gwmi Win32_OperatingSystem -ComputerName $_.name | Select Caption,ServicePackMajorVersion
    $WinCompSys = gwmi Win32_ComputerSystem -ComputerName $_.name | Select Model,Manufacturer
    $WinBIOS = gwmi Win32_BIOS -ComputerName $_.name | Select SerialNumber
    $serverInfo.SerialNumber = $WinBIOS.SerialNumber
    $serverInfo.Caption = $winOS.Caption
    $serverInfo.ServicePackMajorVersion = $winOS.ServicePackMajorVersion
    $serverInfo.Model = $WinCompSys.Model
    $serverInfo.Manufacturer = $WinCompSys.Manufacturer
    $serverInfo
    } | Export-Csv compinfo.csv -NoTypeInformation
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    16 Mar 2010 08:44 AM
    oh wow, cool I never thought of building the script and output that way, thanks!
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    16 Mar 2010 10:05 AM
    how about pointing to an OU an running the same script instead of using th input file, that can be accomplished by building a variable and using a foreach against it, correct?
    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:352
    Avatar

    --
    16 Mar 2010 10:30 AM
    Sure.  Not much has to be changed either.  All you need is to replace the import-csv with Get-QADComputer.  I put the OU in a variable in order to shorten the main command.


    $DN = "distinguishedName" #you could also use canonical name  "domain.com/ou1/subou"            
    $serverinfo = "" | select Caption,ServicePackMajorVersion,SerialNumber,Model,Manufacturer
    Get-QADComputer -IncludedProperties name -SearchRoot $DN -SearchScope subtree |
    %{ $winOS = gwmi Win32_OperatingSystem -ComputerName $_.name | Select Caption,ServicePackMajorVersion
    $WinCompSys = gwmi Win32_ComputerSystem -ComputerName $_.name | Select Model,Manufacturer
    $WinBIOS = gwmi Win32_BIOS -ComputerName $_.name | Select SerialNumber
    $serverInfo.SerialNumber = $WinBIOS.SerialNumber
    $serverInfo.Caption = $winOS.Caption
    $serverInfo.ServicePackMajorVersion = $winOS.ServicePackMajorVersion
    $serverInfo.Model = $WinCompSys.Model
    $serverInfo.Manufacturer = $WinCompSys.Manufacturer
    $serverInfo
    } | Export-Csv compinfo.csv -NoTypeInformation
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    16 Mar 2010 10:40 AM
    One important thing to note is Export-CSV won't append a file.  Try this:
    $DN = "distinguishedName" #you could also use canonical name  "domain.com/ou1/subou"            
    $data = @()
    $serverinfo
    = "" | select Caption,ServicePackMajorVersion,SerialNumber,Model,Manufacturer
    Get-QADComputer -IncludedProperties name -SearchRoot $DN -SearchScope subtree |
    %{ $winOS = gwmi Win32_OperatingSystem -ComputerName $_.name | Select Caption,ServicePackMajorVersion
    $WinCompSys = gwmi Win32_ComputerSystem -ComputerName $_.name | Select Model,Manufacturer
    $WinBIOS = gwmi Win32_BIOS -ComputerName $_.name | Select SerialNumber
    $serverInfo.SerialNumber = $WinBIOS.SerialNumber
    $serverInfo.Caption = $winOS.Caption
    $serverInfo.ServicePackMajorVersion = $winOS.ServicePackMajorVersion
    $serverInfo.Model = $WinCompSys.Model
    $serverInfo.Manufacturer = $WinCompSys.Manufacturer
    $data += $serverInfo
    }
    $data | Export-Csv compinfo.csv -NoTypeInformation

    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    cameronoveUser is Offline
    Basic Member
    Basic Member
    Posts:352
    Avatar

    --
    16 Mar 2010 12:51 PM
    Hmm. That's odd. I wonder if there is a version issue here. I tested the script before I posted and all the servers in my import file exported properly into my export file. I just verified the file that it created and sure enough all the servers in the import.csv are in the export csv. I didn't test the Get-QADComputer version though.

    I'm using v2 RTM with Windows 7. Maybe that's the difference.

    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    16 Mar 2010 02:01 PM
    That could be. All my tests are on dinosaurs...XP Sp3 and 2003 R2 SP2.
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer