Solved

Powershell script to generate a report of all computers in OU

Posted on 2014-10-22
10
827 Views
Last Modified: 2014-10-29
I need to create a PowerShell script which will generate a report for me of all computers in OU.

Report needs to be formatted as html or excel file and should look like this:

Name                OperatingSystem                                     Description
---------                --------------------------                                   -----------------
Server2             Windows Server 2008 R2 Standard     File Server
Lync13Srv        Windows Server 2008 R2 Standard      Lync 2013 Server
Server20          Windows Server 2012 R2 Standard      Standalone Hyper-V Server

Note: Report must have 'Description' field
 
Thanks in advance
0
Comment
Question by:Olevo
10 Comments
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40398469
something along this line will work

$computers = Get-ADComputer -LDAPFilter "(name=*)" -SearchBase "CN=Computers,DC=Fabrikam,DC=com"
foreach ($computer in $computers)
{
Get-WmiObject -Class Win32_OperatingSystem -ComputerName $computer | Select-Object -Property * | select PSComputername, Name ,Description | export-csv c:\example.csv 
}

Open in new window

0
 
LVL 1

Author Comment

by:Olevo
ID: 40398508
Thanks David, my PowerShell skills is not up to the speed just yet. Please correct me if I wrong. First you get the list of all computers (Get-ADComputer) in OU and then you‘re querying (connecting to) computer with WMI command (Get-WmiObject) to get additional info. I’m I right? If this the case we will have problem getting info from the computers which are not online (switched off). All I want is to get info from Domain Controller… Perhaps, we can get ‘Description’ info from ‘Attribute Editor’
Attribute Editor
0
 
LVL 5

Expert Comment

by:Mai Ali (MVP)
ID: 40398990
For script that list all computers on ou, you can check below link
http://www.hofferle.com/generating-lists-of-computer-names-with-powershell/
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40399714
Here is a 1 liner

Get-ADComputer -filter * -SearchBase "OU=Servers,DC=Fabrikam,DC=com" -properties Name,OperatingSystem,Description | Select Name,OperatingSystem,Description | Export-CSV C:\ServerInfo.csv -nti

Open in new window

0
 
LVL 1

Author Comment

by:Olevo
ID: 40400663
Thanks Joshua, that is exactly what I want. May I trouble you for an additional request? How hard it would be to make something like this: Our internal web site will have a page with a link, when I click on it, code within a web page (PowerShell command above)  will generate Servers information (Name,OS, Description, etc.) as a nice formatted html table.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40400666
What is your internal website hosted with?
0
 
LVL 1

Author Comment

by:Olevo
ID: 40400812
Thanks Joshua, This "Company Servers information" web page will be running on IIS 8.5 (Windows Server 2012 R2). Basically I need this page for my manager, so he can see list (click on a link) all our servers and what they do (Description) in our AD domain any time he wants. I'm guessing that it would be much easier just to run PowerShell script as a schedule task instead of fulling around with the web development?! Anyway, what do you think how I should accomplish my goal?
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40400847
Tomorrow I will modify the powershell script to output to an HTML document, then you can just have an HTML link to the output file.

Then you can run the powershell as a scheduled task and it will update the html file on whatever schedule you want. Simple as that.
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40402199
Here you go! This has basic styling but you can modify that how you like if you want to add color or adjust spacing.

#Page Title
$title = "Server Information"
#HEAD Section (CSS for Styling)
$head = "<style> BODY{background-color:#FFFFFF;} TABLE{width: 75%; border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} TH{border-width: 1px;padding: 10px;border-style: solid;border-color: black;background-color:#999999} TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#FFFFFF} </style>"
#Page Header
$body = "<H2>Information about Servers in $search</H2>"
#Path to save html report
$path2output = "C:\ServerInfo.html"
#OU to query for report
$search = "OU=Servers,DC=DOMAIN,DC=com"

Get-ADComputer -filter * -SearchBase $search -properties Name,OperatingSystem,Description | ConvertTo-Html Name,OperatingSystem,Description -title $title -head $head -body $body | Set-Content $path2output

Open in new window

0
 
LVL 1

Author Comment

by:Olevo
ID: 40412472
Thanks Joshua that is exactly what I want
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question