Why I no longer hate writing documentation…
…it’s because I no longer have to! And you too will no longer document your computers and servers either. Why? Because PowerShell is going to do it for you and I’m going to share with you how I did it. Yes, it is going to be presented well, in Excel, and the Boss is going to think that you are the greatest thing since sliced bread.
Computer Inventory
I picked up a side job at the beginning of the year documenting the infrastructure for a company that will remain anonymous at this time. It doesn’t surprise me that many companies still do not maintain up-to-date documentation if any. What is the “BIG DEAL” about documenting a system, is it really a “time factor” problem or “lack of resources” to do the job? I, like many of my peers, just think documenting SUCKS!!! So I set out to make my life and hopefully yours a little easier.
The Computer Inventory Script enumerates Hardware, OS, System, Processor, Memory, Disk, and Network information and neatly organizes it in an Excel file. I’ve provided Version 2 of the script that allows you to choose a number of computer resources; all computers in the domain, all servers in the domain, computers from a list maintained in a text file, and the ability manually pick a computer. Version 2 of the PowerShell script also allows you to send credential information should you wish to logon the remote computer with an alternative user account. This is helpful for DMZ servers as well as stand alone servers that are not members of your domain.
Please feel free to customize this script to fit your environment. I’m not going into any detail about the script as I am reserving that information for a new PowerShell tutorial that I am writing about COM objects. So check the tutorial section to for more information.
Here is the code so that you can view it before downloading. I would suggest downloading this file as format issues with copying the code below may occur.
Email This Post To A Friend
« Conficker Worm Detection | Home | How do I know if I’m missing MS Patches? »
Comments
Wow! What a great script! Just ran it for the first time. The way the results are capture in Excel is impressive.
Thanks, this helps a lot!!!
Love it. Unfortunately I can’t get it to work with Office 2007.
It just starts Excel, doesn’t create a sheet with information.
For the record I am using Office 2003. I’ll get a copy of Excel 2007 and test the code…
Tested script with Excel 2007 and it works. It may be the option you are choosing. If you are choosing the option to gather info from “All Computers” or “All Servers” in your domain, it may take a long time to enumerate all the information. Try Option [4]Choose a Computer manually to test enumerating from a single computer.
DUDE!!! This is the best! The memory sheet is my favorite love that I can see the number of slots, what size RAM is installed, and which slots are empty. Makes memory upgrades much easier without having to power down and opening the box.
Hmm ok, that’s what I tried. Will make it run a bit longer and see.
The problem with empty Excel is with the current locale. Set current locale to “en-US” and it will work.
Would it be possible to add a software installed tab.
Hi there..
I been trying to find the Set current locale to “en-US” and tried replacing the code however no luck and help would be appreciated
#New Excel Application
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
with
$ci = new-object globalization.cultureinfo en-US
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel.UserControl= $True
$Sheet = $Excel.Workbooks
$Sheet.PSBase.GetType().InvokeMember(“Add”,
[reflection.bindingflags]::InvokeMethod,$null, $Sheet, $null, $ci)
I added this function
# ========================================================================
# Function Name Select-FileDialog #
# Created by Hugo Peeters #
# http://www.peetersonline.nl #
###############################
# Example use:
# $file = Select-FileDialog -Title “Select a file” -Directory “D:\scripts” -Filter “Powershell Scripts|(*.ps1)”
function Select-FileDialog
{
param([string]$Title,[string]$Directory,[string]$Filter=”All Files (*.*)|*.*”)
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”) | Out-Null
$objForm = New-Object System.Windows.Forms.OpenFileDialog
$objForm.InitialDirectory = $Directory
$objForm.Filter = $Filter
$objForm.Title = $Title
$Show = $objForm.ShowDialog()
If ($Show -eq “OK”)
{
Return $objForm.FileName
}
Else
{
Write-Error “Operation cancelled by user.”
}
}
# ==============================================================================================
And changed the line
$strText = Read-Host “Enter the path for the text file”
To
$strText = Select-FileDialog -Title “Select a file” -Directory “c:” -Filter “Text Files (*.txt)|*.txt”
now I can browse to select the text file of computers.
I get an error when excel opens too..
Which computer resources would you like in the report?
Exception calling “Add” with “0″ argument(s): “Old format or invalid type library. (Exception from HRESULT: 0×80028018 (TYPE_E_INVDATAREAD))”
At :line:390 char:29
+ $Excel = $Excel.Workbooks.Add <<<< ()
can someone send me final version of this script, I cannot configure it to run with excel 2007.
matiss(dot)baltalksnis@gmail.com
This script is great but i am new to powershell and need the uptime of the servers added to this script, how to do that????
Hi, How do I change this script to output to notepad, we do not have Excel?
Thanks
Can someone recomend a good book on PowerShell, for a beginner
This looks great – however when choosing option 1 for all domain computers only one machine shows up. No errors pop up but in the debug window I see the following:
“Which computer resources would you like in the report?”
Undetermined
Undetermined
Any help would be appreciated.
Thanks,
Brian
I’m a beginner when it comes to scripting and likewise in Powershell.
I would love to get this script working but i have only ended up with a blank excel, not even a worksheet.
I have tried it in two setups.
In both setups I ran it on local machine.
1.Vista Business SP2 Office 2010 Beta
2.XP SP3 Office 2003
Vista is fysical, XP is virtual(would have liked it to be the other way around).
I checked to see if all COM and WMI services were running – ok.
In Vista I allowed powershell in Firewall.
In XP I disabled firewall.
In Office2010 Beta i set folder, and subfolder of powershell-exe to be trusted.
Starting to suspect it could relate to some module missing in powershell or something else missing.
I have complete faith this is a wonderful script. But since you guru’s have been working with scrips so long I suspect this script does not work since I and other don’t meet the pre-requisites.
Is there anyway to find out pre-requisites, dependencies..
Thank you for shareing all you’re knowledge
Best Regards
/Bengt
I forgot to mention that i tried Jamey Westmoreland textversion provided in this thread. It resulted in me being posted to save the textfile numerous times as specified in the script but there were never any textfiles saved.
I also tried editing the script to use OpenOffice Calc instead (it’s installed next to Office 2010 Beta on my Vista-machine) but I was never able to “wake” Calc through the script.
Regards
/Bengt
To optimize the scan, I added a check to skip non-responding computers (e.g. linux machines, computers turned off, and unupdated AD records). Scanning of our network is a lot faster now.
Function WMILookup {
foreach ($StrComputer in $colComputers){
$GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
***********
if(!$GenItems1){
Write-Host “$StrComputer not found”
continue
}
***********
Thanks for the script! I also love your tutorials, especially the real-world examples. Very well written!
Menno
using powershell 2.
created a simple script to output the computer names and descriptions.
Trying to output from a specific OU to a spreadsheet and format the two fields: name and description with no luck so far.
here’s the script:
$strFilter = “computer”
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = “LDAP://servername/OU=laptops,ou=city,DC=domain,DC=com”
$objSearcher.SearchScope = “subTree”
$objSearcher.PageSize = 1000
$objSearcher.Filter = “(objectCategory=$strFilter)”
$colResults = $objSearcher.FindAll()
foreach ($i in $colResults)
{
$objComputer = $i.GetDirectoryEntry()
Get-WMIObject Win32_BIOS -computername $objComputer.Name,$objComputer.Description
}
Help would be appreciated. thanks.
Hi, in Excel 2010 it works only if add:
$culture = [System.Globalization.CultureInfo]“en-US”
$oldCulture = [System.Threading.Thread]::CurrentThread.CurrentUICulture
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
just before Excel calling.
Thanks for script
I tried to run this script but it will open a blank excel 20007 sheet. Could you please update me if i am doing anything wrong? I have not modified anything within the script.
Can another sheet be added so it inventory software that is on the local hard drive?
software inventory would be nice…
This is a sample code that lists inventory software I found..
Only thing is integrate this into excel file..
$RegPath= “SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”
$BaseKey =[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(“LocalMachine”, $ComputerName)
$OpenSubKey = $BaseKey.OpenSubKey($RegPath)
$file = localhost
foreach ($obj in $file) {
$OpenSubKey.GetSubKeyNames() | foreach {
$BaseKey.OpenSubKey(“$RegPath\$_”).GetValue(“DisplayName”)
}
}
Bman: Best guess is the line with the word Undetermined should actually read:
default{$Sheet5.Cells.Item($intRowDisk, 2)=”Undetermined”}
Menno: Thanks for the optimization!
Brilliant, just brilliant…
would it be possible for the ip address to be imported in the columns next to each other instead of the row below it? If so how would i do that.
Love the script! it has saved me weeks of work
This script is great. Added the code needed to drive the progress bar properly.
Way to go! Just ran the script on a Win7 SP1 desktop to a WinXP SP3 box and was floored by the process. A little more testing and I’ll try it on my servers.
I’m not sure if you’re still working on this, but I’m unable to run the script against my local PC (Win7 SP1). I’ll have to try it out on an XP machine.
Thanks!
This is awesome!! I’m new to scripting and powershell. Is there a way to add the logged on user to the script?
Awesome script for getting inventory on servers, however it can seem to get information on all our windows 7 clients? any ideas on this? ( i know our clients are locked down pretty tightly, firwall maybe? )
This script is very useful. However, I am trying to populate which user is on which computer (by looking at the last user to log in).
How can I manipulate the script below to do the network and add it into the excel sheet?:
$data = @()
$NetLogs = Get-WmiObject Win32_NetworkLoginProfile
foreach ($NetLog in $NetLogs) {
if ($NetLog.LastLogon -match “(\d{14})”) {
$row = “” | Select Name,LogonTime
$row.Name = $NetLog.Name
$row.LogonTime=[datetime]::ParseExact($matches[0], “yyyyMMddHHmmss”, $null)
$data += $row
}
}
$data
Hmmm…I wonder if this could be sent to a csv file. For example, then you could simply imnport into Excel if you must run it from a server that cannot have MS Office installed.
This is an awesome script, we are going to try at our campus, but we need it to one more thing…
It needs to get the computers serial numbers…where and how would I enter that code in…or if you could email me a version with the code already added…that would be great!
script is good and working in my domain, but i want to know how we can wrtite script to work only one OU ratherthan complete domain.
How about the serial number? Can we add that as well?
Thanks for sharing.
I would suggest you check out the the following:
The Microsoft Assessment and Planning Toolkit.
I found it will do all things this script will do, and give some other information you might find useful, like can this machine be virtualized!
http://technet.microsoft.com/en-us/library/bb977556.aspx
Awesome tool. @Peter, yes we could but I don’t want to install SQLX.
Excellent script!!!.
Is there any possibilty to generate & save the report in CSV format instead of opening in Excel.
As we should not install office in any of the production server. though we have the possibility to install management tools in workstation.
If the file is saved in csv or excel format we can enhance the script and send a mail to the admin DL.
Please suggest.
Hello
I’m working at the saving part too.
But i have no success. I think the script ignore my lines:
$workbook.SaveAs(‘c:\Files\inventarlist.xlsx’)
$workbook.Close()
$excel.Quit()
Maybe somebody can help me out with this problem.
Thanks in advance!
reagards, sebastian
Thank you for your prompt response.
Please do let me know if you are ready with the script.
Kindly let me know if we can get the mount point information along with the disk space report.
Once again Thanks
Hi Jesse,
Don’t laugh. I’m new to Powershell scripting and love the idea of creating a good inventory without having to run all over the office, climbing on the floor under desks, etc. I’m running Windows 2008 R2 Server. Most of our systems are Win7 with one XP hold out. I did try to run the script, but when I choose “1″ for all systems, it just says undefined 15 times, then closes. There’s no report generated. It may have to do with the fact that we don’t have excel on the server, and I can’t put it on there. If this is the cause, is there a way around it? If that would not be the cause of this, can you give me a little insight as to what I should try? I’m determined to make this work!
Thanks for writing such a great script!
Great script for a relative Powershell n00b to get started with.
I need to make one SMALL change, and for the life of me I can’t see where it should go.
On our machines we have a file c:\windows\soe.txt – I need to write the first line of this file (the SOE version) to an additional column in the general sheet
Would you be able to point me in the right direction ?
@Elizabeth
Same problem here
@Nate @Elizabeth
Run it from a workstation with excel installed. It doesn’t have to be run from a server, just a computer with PS, Excel, and appropriate AD rights.
Hi Jesse,
The script works like a charm. Is the available script work with excel 2003/2007/2010. Also, let me know how I can merge into one sheet.
Thank you in advance.
Venkat
Thanks. This is awesome.
Thank you for the script! I would gladly contribute to a paypal donation for your work.
Very nice script; thanks for publishing!
Thanks… this is MUCH better than the stripped down version of something someone here wrote – MUCH better!
Awesome job, and thanks for sharing!
Such a brilliant script, yep its going to save my weeks of efforts. Thanks so much Jesse.
Really a good script, very helpful
Fantastic script, has anyone managed to amend the script to return the current user logged on to the PC?
I love it..Thanks!! works like a charm..
@Ryan
Here’s what I’ve been using.
http://pastebin.com/yCymqgZK
Modified version of this one. Way less info but only the stuff I need. Should work for you.
I’ve been trying out the script and it’s great.. I notice however that it probably receives a response from one of my servers which seems to stop it right in its tracks.
I used a text file as input this time excluding the two servers to whom powershell had a connection open to. It continues happily now..
Simply marvelous, the way data output is segregated and way it’s written, with all the comments.
Great script, thank you!
Fantastic!!! I also would like to thank Menno for the modification changes to exclude computers which are not reachable.
What a great script!!!!… thanks a ton
Great script… Ran great on small set.
If I had serial numbers,I could then look up warrantee dates. Did anyone add this?
Thank you to everyone especially Jesse!
I know this is probably a dumb question, but when I run the script, it does not prompt for a choice to pick an option. Am I missing something ?
Thanks for any help
Nevermind, I wasn’t running with powershell I was just copying and pasting the code. It is working now
Wonderful script. Thank you!
Can I use this script if I’m not on a Domain? If yes, how? All PC’s on my network are on specific workgroups e.g.: Factory1, Factory2, HR, Storage, etc.
Awesome script…appreciate it.
You are a Genius!!!
Awesome script, thank you for taking the time to write and publish for others to use. It worked perfectly documenting all of my Citrix servers from a text file. Again thanks!!!
Great script, runs perfect !
and my boss is going to think that you are the greatest thing since sliced bread.
This is awesome. Thank you so much.. I’m gonna need to start writing in functions too
Beautiful!!
I am a super newbie to powershell so i apologize upfront. Im looking in this script as to where i change it to point to a .txt file for the list of computers. Thanks so much for your time and for writing this script.
@Dave
You don’t need to modify the script, just run it. It will ask you for the location of the txt file through prompts.
Hi,
Awesome script btw… well done. I am new to all this PS stuff, but can see massive benefits and learning from you all is just such a buzz, however, I am coming a cropper on a few things. I run the script, no issue, but I get the response “Undetermined” coming up as the script is running, the excel file does populate with some devices, but not workstations etc… this happens even if I run the script under admin creds or not. Any advice on that? Also, if I use a text file with device names in it, the script just kinda seems to hang and do nothing in the SS…. am I being too impatient? Any advice or help rally appreciated.
Fantastic script! Help me in finding the necessary server information from my domain. Thanks!!!!
Excellent script! First one out of the box that did everything I needed it to do. I am a newbie to PS, and I am trying to add a few parameters and wondering if I can use your expertise. I would like to add the MAC address to the network output. In addition to the address, is there a way to add each physical adapter? It is only showing 1 adapter when it is teamed. Any advice would be greatly appreciated.
How to add graphic’s card to inventory.
Only list one DNS Server with $objItem.DNSServerSearchOrder. Anyone can help me?
I got Windows 2008 R2
Great script thanks a lot for such a brilliant job
Thank you
Great script, I love it!!!
One small problem I’ve found, it does not report any data from our Windows 2003 servers. Any ideas of what could cause it?
The windows firewall is not enabled on this servers and WMI is running.
I got this script running out of the box and the details are just what I’m after. I do wonder how it scans “all domain computers” because the results being returned are scattered across different subnets and OUs; I don’t see the order behind it.
I’m pretty green when it comes to any scripting but an option to scan by OU would be great for more targeted results without having to first export the OU listing to a txt file. How can I add this?
Thanks,
Cameron
Awesome script!
Is there any way of scheduling the script to scan all domain computers?
)
I’m a Primary school technician and I have 9 schools to visit each week. Half a day isn’t enough to take a manual inventory as well as doing other requests. If I could schedule the scan at odd times of the day, collecting information as the laptops are not always on. Don’t mind if it would accumulate with many open Excel documents, just knowing what the schools have would be a huge help to me (and our sales team
LIke many of the others here I am relatively new to scripting so I am very green. I came across your script because I need to roll local admin passwords on all of computers so I need a list of all of the member machines on our domain.
Your script is AWESOME and is providing me with a lot of information. Most of the results are coming back with only the Device_Name (which is actually what I need so things are good) but the other data that is returned for other machines is stuff that is valuable as well.
Am I missing something or is there something I need to modify to get the data I need?
My DCs are 2k3.
The following script includes many of the suggestions posted here, plus a few of my own:
a) Include tabs for installed software, b) Roles and Features, and c) Scheduled tasks
b) Skip computers that cannot be accessed
c) Display the computer name being skipped or inventoried (if it is accessible or not)
d) When default switch action was “undetermined”, write to Excel file instead of screen.
e) Added compatibilty for Excel 2010 and 2013. (set culture to “us-en”)
f) Updated prompt for txt file dialog
The script can be downloaded from http://pastebin.com/3R7uveJs
Thanks for sharing Jeff!
My previous pastebin link pointed to the wrong version of the script. Please use this version instead: http://pastebin.com/GSemjRLe
Leave a Comment