hardware and software inventory Collection From AD or Txtfile into Excel sheet

the script takes a number of servers as an input and produces custom objects with certian properties like (name , rams , cpu , installed applications ...) which can be pipelined to export-csv to produce an excel readable file

 
 
 
 
 
4.3 Star
(13)
Add to favorites
Operating System
3/12/2010
E-mail Twitter del.icio.us Digg Facebook
  • no result?
    1 Posts | Last post October 12, 2013
    • Great script.
      I have text file which includes all servers name.
      Now, I use Get-Content c:\info\servers.txt | .\get-hostinfo | Select Name , IPaddress , Srvmodel | Export-csv C:\output.csv
      no result.  should this work with txt file instead of security group?
      
      Thank you.
  • Nice script....request
    1 Posts | Last post August 01, 2011
    • Nice script do you know how to get it to query Ad group with nested groups?
      
  • Got csv export to work... with a few changes
    5 Posts | Last post July 24, 2011
    • #Get-Content c:\servers.txt | Select Name , IPaddress , Srvmodel | Export-csv C:\output.csv
      
      The line above did not call the function. Added and it worked fine (see below). 
      
      #Get-Content c:\servers.txt | get-hostinfo | Select Name , IPaddress , Srvmodel | Export-csv C:\output.csv
      
      I also receive the try errors but it completes and creates the output.csv. Thanks for the hard work.
      
      
      
    • Welcome Kerry , Glad i could help
      you can also try out-gridview if you are using PS v 2
      Get-Content c:\servers.txt | get-hostinfo | Select Name , IPaddress , Srvmodel | Out-GridView
    • Hi Mohamed,
      I checked this script it perfectly works, thanks alot for your work. Is it possible to add one additional value for me, i did this but facing few challenges.
      1. I required Paging file information with the below properties Initialsize, Maximumsize,count 
    • this can be done , i will get back to you soon with that , i can't really test that now
    • Hi All,
      
      Could you please explain how to execute the script in step by step...
      
      I m very new to scripting..thanks to do the needful.
  • Output Results
    3 Posts | Last post September 28, 2010
    • Mohamed, thanks for posting this script.  I'm new to scripting and want to learn Powershell.  I've tried to modify it to fit my needs, but I'm not getting any results.  I was hoping you could help.  I've uncommented "$servergroup=[ADSI]"LDAP://....." and entered the appropriate OU information.  I've also uncommented "$groupmembers | get-hostinfo | Select Name , IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors, Applist | Export-Csv c:\folder\path\etc\spiderresult.csv" and changed the path to a writeable location on my hard drive.  The script runs without any errors and it creates the file "spiderresult.csv", but there is no information listed in the file.  The OU that I'm querying contains 2 computers that are on the network.  One of them is running Windows 7 and the other is running Windows XP SP3.  Do you have any ideas as to why I'm not getting any results.  Thanks for your time.
    • Well, I feel silly.  I didn't have the systems in a "security group".  I was querying the OU thinking that would work.  I added the systems to a group and queried it and it worked like a champ.  I guess the next step for me is to learn how to query OUs and figure out this pipeline thing. :)
      Thanks for the awesome script.
    • don't worry about that :) 
      welcome 
  • How do you run this power shell script?
    8 Posts | Last post June 18, 2010
    • Okay I am brand new to systems administration with scripting. I copied the script and called it Computers.ps1
      
      then i opened it up in PowerShell ISE.
      
      Where i get confused is below the script starts here... everything is commented out. Am i supposed to uncomment something or add my ldap settings in the script itself?
      
      Would greatly appreciate any help. I am trying to learn power shell. And I greatly need a listing of all my machines with what kind of hardware etc... they have.
      
      thanks,
      
      Pete
      
      
    • hi pete , 
      i've divided the post because of the max characters limit
      you have chosen the right thing with powershell then :) 
      yes you need to comment stuff out if you want to connect to AD and grap computers
      provided that you run this script from a computer joined to the domain , and an account having read permission on the active directory also permission to Query WMI from the computers that you want to collect its info
      1- Add the computers that you want to Query to a security group called "servers" on the root of your domain
      2-you will need to comment these 2 lines out
      #$servergroup=[ADSI]"LDAP://CN=Servers,DC=YourDomain,DC=dom" #Set your location for AD group containing servers
      #$groupmembers=$servergroup.member
      
      LDAP://CN=Servers,DC=YourDomain,DC=dom is the LDAP path to the computer group
      
      these 2 lines connect to AD and grap the computers names
      
      you also need to comment this line out
      #$groupmembers | get-hostinfo | Select Name , IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors, Applist | Export-Csv C:\test\spiderresult.csv
      this is the actual command being run , it graps the computers from AD , pipes it into Get-hostinfo function which is defined at the beginning of the script .
    • you can also customize what you want to be displayed ,in the Select Statement , for example Select Name , Srvmodel , responsetime , Rams , Cpuz ... do that depending on what you want to de displayed in the outout
      you can select from different properties ,basicly in the script you will find statements like $Computer | Add-Member NoteProperty ResponseTime ($pingresult.responsetime) .. responsetime is the property here , you can select from all the properties avaliable in the script (anything that comes after noteproperty)
      the last part Export-CSV c:\test\spiderresult.csv exports the output into a csv which can be read nicely from an excel sheet
      
      powershell has a new security feature that requires scripts to be digitally Signed by defualt,so since this script is not signed , you will need to change something
      on the computer that you use to run this script , run powershell.exe as an administrator and type Set-ExecutionPolicy Remotesigned
      this tells powershell that you don't need to check for digital signatures for any local script being run , but do that for only for remote executed script
      i highly advice that you set the execution policy to Allsigned in a production environment which is the powershell default anyway
      but since this script is not signed and you want to run it , you can change it to Remotesigned , then change it back
    • Hmm.. well I am having some issues with getting domain admin rights from our administrators. So i have to go with plan b... I have the below..
      
      # <<<<<<  Script execution Starts HERE  >>>>>>>		
      
      #comment this part out if you want to create a connection to Active directory to get the computer objects
      #connecting to AD to query computers in a security group named "servers"
      #$servergroup=[ADSI]"LDAP://CN=computer,DC=glynncounty-ga,DC=gov" #Set your location for AD group containing servers
      #$groupmembers=$servergroup.member
      
      #Actual command being line (pipeline)
      
      # you can use Get-hostinfo function in the following Ways
      #$groupmembers | get-hostinfo | Select Name , IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors, Applist | Export-Csv C:\test\spiderresult.csv
      #$groupmembers | get-hostinfo | Select Name , OSType , Servicepack ,  IPAddress , Sitelocation , SrvModel , TotalStorageGB , RAMS , CpuMhz , ProcessorCores , PhysicalProcessors , Applist | Export-Clixml c:\test\spiderobj.xml
      Get-Content c:\servers.txt | Select Name , IPaddress , Srvmodel | Export-csv C:\output.csv        #"getting content from alocal file"
      #$groupmembers | get-hostinfo | Select Name , OSType , Rams , Cpumhz  | export-clixml c:\compobjs.xml 
      
      
      if by comment out you mean to remove the #  that is in the front of the Get-Content that is what I did.
      
      I created a text file called servers.txt in the root of my c driver that contains one computer I want to test on. The computer in there I have local admin rights on with my domain account. 
      
      servers.txt file looks like the below for testing.
      
      shrfserver01,
      
      when I execute the script nothing happens outside of it creates the output.csv with the below in it.
      
      #TYPE Selected.System.String
      "Name","IPaddress","Srvmodel"
      ,,
      
      what am I doing wrong?
      
      
    • okay , great now we can test with this server
      you need to remove the , at the end of the server name
      also you will need to remove these 2 lines
      $x=$_.split(",")
      $server=$x[0].Substring(3)
      
      and substitute them with this line
      $server= $_
      
      these 2 lines parse the input from full LDAP path to netbios server name
      so since you are already passing to the function a netbios name you set the $server to value of the pipelined object
      
    • Hi Mohamed,
      I checked this script it perfectly works, thanks alot for your work. Is it possible to add one additional value for me, i did this but facing few challenges.
      
      1. I required Paging file information with the below properties Initialsize, Maximumsize,count 
    • page file info with Initialsize, maximumsize, count and caption. In our environment we have set 2 pagefile on few servers. SO please help me and i am planning to have it in this script itself.
    • hello
      i think what you are looking from is in WMI Win32_pagefileusage or Win32_Pagefile , anyway if you still need these properties tell me and i will be happy to add them for you