?
Solved

Powershell script to generate a report of all computers in OU

Posted on 2014-10-22
10
Medium Priority
?
1,076 Views
1 Endorsement
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
1
Comment
Question by:Olevo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 82

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

771 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