Skip to content

Instantly share code, notes, and snippets.

@theagreeablecow
Created May 26, 2012 22:52
Show Gist options
  • Save theagreeablecow/2795543 to your computer and use it in GitHub Desktop.
Save theagreeablecow/2795543 to your computer and use it in GitHub Desktop.
Server Inventory from Active Directory
# This script will generate a list of all servers in AD, collect inventory items and export to Excel
# Requires the Active Directory module for Windows Powershell and appropriate credentials
#LOAD POWERSHELL SESSIONS
#------------------------
$DC = "dc1.maydomain.com.au"
$usercredential= get-credential -credential mydomain\admin
$Path = "\\mydomain.com.au\Scripts\Data\"
$ExportFile = $Path + "ServerInventory.csv"
cls
write-host -foregroundcolor Green "Loading Active Directory Module"
import-module ActiveDirectory
#Get AD Data
#-----------
Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -Property * | Select-Object Name,Enabled,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,DistinguishedName,whenCreated,LastLogonDate,whenChanged | sort name | Export-CSV $ExportFile -NoTypeInformation -Encoding UTF8
#Get-ADComputer -Filter {OperatingSystem -Like "Windows *Server*"} -Property * | Export-CSV $ExportFile -NoTypeInformation -Encoding UTF8
Invoke-Item $ExportFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment