Skip to content

Instantly share code, notes, and snippets.

@mercdev
Created May 2, 2015 23:08
Show Gist options
  • Save mercdev/04d67d58044500546b97 to your computer and use it in GitHub Desktop.
Save mercdev/04d67d58044500546b97 to your computer and use it in GitHub Desktop.
PowerShell Windows AD Inventory with Excel output
# Usage: Audit.ps1 'pathtolistofservers' #
# The file is optional and needs to be a plain text list of computers to be audited one on each line. #
#
param([string] $auditlist)
cls
$Error.Clear() # clear the stack
$targets = $null
if ($auditlist -eq "")
{
Write-Host "No server list specified. Using Default."
$defaultList = "## LOCATION TO YOUR serverlist.txt FILE HERE ##"
if (Test-Path $defaultList)
{
$targets = Get-Content $defaultList
}
else
{
Write-Host "Default '$defaultList' not found. Finding all servers in current Domain..."
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher.Filter = "(&(objectCategory=computer)(operatingSystem=*Server*))" #servers only
#$objSearcher.Filter = "(&(objectCategory=computer))" # all computers
#$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc=YOUR_DC_HERE,dc=org")
$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry("LDAP://dc=YOUR_DC_HERE,dc=local")
$objSearcher.PropertiesToLoad.Add("name")
$objSearcher.Sort.PropertyName = "name"
foreach ($objResult in $objSearcher.FindAll())
{
$targets = $targets + $objResult.Properties["name"];
}
}
}
else
{
if ((Test-Path $auditlist) -eq $false)
{
Write-Host "Invalid audit path specified: $auditlist"
return
}
else
{
Write-Host "Using Audit list: $auditlist"
$targets = Get-Content $auditlist
}
}
$Credentials = Get-Credential "DOMAIN\USERNAME"
$SaveFilename = "## PATH TO SAVE YOUR Server_Data.xlsx FILE TO ##"
$excel = New-Object -comobject Excel.Application
$excel.visible = $false
$wbook = $excel.Workbooks.Add()
#$wbook.Worksheets.Item(3).Delete()
#$wbook.Worksheets.Item(2).Delete()
#$wbook.Worksheets.Item(1).Delete() #must have at least one worksheet
$date = $(Get-Date –f MM-dd-yyyy)
$wsheet = $wbook.Worksheets.Item(1)
$wsheetCount = 0
foreach ($Target in $targets)
{
$iRow = 1
Write-Output "Contacting $Target..."
if ((Test-Connection -ComputerName $Target -Quiet -Count 1 -BufferSize 16) -eq $false)
{
Write-Output "$Target unavailable. Adding generic entry..."
$wsheet = $wbook.Worksheets.Add()
$wsheet.Name = $Target +" (Offline)"
continue
}
try
{
$ComputerSystem = Get-WmiObject -ComputerName $target -Class Win32_ComputerSystem -Credential $Credentials -ErrorAction SilentlyContinue
}
catch [System.UnauthorizedAccessException]
{
Write-Output "Unable to connect to {$Target}, Unauthorized."
$wsheet = $wbook.Worksheets.Add()
$wsheet.Name = $Target +" (Unauthorized)"
continue
}
catch [System.Exception]
{
#terminating exception handler
Write-Output $Error
continue
}
if ($? -eq $false)
{
Write-Output " Error contacting {$Target}: $Error"
$Error.Clear() #keep it from appending to the stack
continue
}
if ($ComputerSystem -eq $null)
{
Write-Output " $Target not found, moving on..."
continue
}
if ($wsheetCount -ge 1)
{
$wsheet = $wbook.Worksheets.Add()
}
#resize printable area
$wsheet.PageSetup.Orientation = 2 #1 - portrait, 2 - landscape
$wsheet.PageSetup.TopMargin = .25
$wsheet.PageSetup.LeftMargin = .25
$wsheet.PageSetup.BottomMargin = .25
$wsheet.PageSetup.RightMargin = .25
$wsheet.PageSetup.FooterMargin = 0
$wsheet.PageSetup.HeaderMargin = 0
$wsheet.Name = $ComputerSystem.Name +" "+ $date
switch ($ComputerSystem.DomainRole)
{
0 { $ComputerRole = "Standalone Workstation"; break }
1 { $ComputerRole = "Member Workstation"; break }
2 { $ComputerRole = "Standalone Server"; break }
3 { $ComputerRole = "Member Server"; break }
4 { $ComputerRole = "Domain Controller"; break }
5 { $ComputerRole = "Domain Controller"; break }
default { $ComputerRole = "Information not available" }
}
$Processors = Get-WmiObject -ComputerName $Target -Class Win32_Processor -Credential $Credentials
$OperatingSystems = Get-WmiObject -computername $Target -Class Win32_OperatingSystem -Credential $Credentials
$TimeZone = Get-WmiObject -computername $Target -Class Win32_Timezone -Credential $Credentials
$Memory = Get-WmiObject -ComputerName $Target -Class Win32_PhysicalMemory -Credential $Credentials
# requires Dell Open Manage Client, not for servers!
#$Memory = Get-WmiObject -ComputerName $Target -Namespace "root\DellOMCI" -Class "Dell_PhysicalMemory" -Credential $Credentials
$SystemItems = Get-WmiObject -ComputerName $Target -Class Win32_SystemEnclosure -Credential $Credentials
switch ($ComputerRole)
{
"Member Workstation" { $CompType = "Computer Domain"; break }
"Domain Controller" { $CompType = "Computer Domain"; break }
"Member Server" { $CompType = "Computer Domain"; break }
default { $CompType = "Computer Workgroup"; break }
}
$wsheet.Cells.Item($iRow,1) = "Computer Name"
$wsheet.Cells.Item($iRow,2) = $($ComputerSystem.Name)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Computer Role"
$wsheet.Cells.Item($iRow,2) = $ComputerRole
$iRow++
$wsheet.Cells.Item($iRow,1) = "Type"
$wsheet.Cells.Item($iRow,2) = $CompType
$iRow++
$wsheet.Cells.Item($iRow,1) = "Domain"
$wsheet.Cells.Item($iRow,2) = $($ComputerSystem.Domain)
$iRow++
$wsheet.Cells.Item($iRow,1) = "OS"
$wsheet.Cells.Item($iRow,2) = [string]::Format("{0} {1}", $OperatingSystems.Caption, $OperatingSystems.OSArchitecture)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Service Pack"
$wsheet.Cells.Item($iRow,2) = $($OperatingSystems.CSDVersion)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Manufacturer"
$wsheet.Cells.Item($iRow,2) = $($ComputerSystem.Manufacturer)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Model"
$wsheet.Cells.Item($iRow,2) = [string]::Format("{0} {1}", $ComputerSystem.Model, $ComputerSystem.SystemType)
$iRow++
$chassisType = $null
foreach($item in $SystemItems)
{
$wsheet.Cells.Item($iRow,1) = "Service Tag"
switch ($item.ChassisTypes)
{
"1" { $chassisType = "Other"; break }
"2" { $chassisType = "Unknown"; break }
"3" { $chassisType = "Desktop"; break }
"4" { $chassisType = "Low-profile desktop"; break }
"5" { $chassisType = "Pizza box"; break }
"6" { $chassisType = "Mini tower"; break }
"7" { $chassisType = "Tower"; break }
"8" { $chassisType = "Portable"; break }c
"9" { $chassisType = "Laptop"; break }
"10" { $chassisType = "Notebook"; break }
"11" { $chassisType = "Hand-held"; break }
"12" { $chassisType = "Docking station"; break }
"13" { $chassisType = "All-in-one"; break }
"14" { $chassisType = "Subnotebook"; break }
"15" { $chassisType = "Space Saving"; break }
"16" { $chassisType = "Lunch box"; break }
"17" { $chassisType = "Main system chassis"; break }
"18" { $chassisType = "Expansion chassis"; break }
"19" { $chassisType = "Subchassis"; break }
"20" { $chassisType = "Bus-expansion chassis"; break }
"21" { $chassisType = "Peripheral chassis"; break }
"22" { $chassisType = "Storage chassis"; break }
"23" { $chassisType = "Rackmount chassis"; break }
"24" { $chassisType = "Sealed- computer"; break }
default { $chassisType = "Unavailable"; break }
}
$wsheet.Cells.Item($iRow,2) = [string]::Format("{0} ({1})", $item.SerialNumber, $chassisType)
$iRow++
}
$BIOS = Get-WmiObject -computername $Target -Class Win32_BIOS -Credential $Credentials
$wsheet.Cells.Item($iRow,1) = "BIOS"
$wsheet.Cells.Item($iRow,2) = [string]::Format("{0}, SMBIOS: {1}.{2}, {3} {4}", $BIOS.SMBIOSBIOSVersion, $BIOS.SMBIOSMajorVersion, $BIOS.SMBIOSMinorVersion, $BIOS.Manufacturer, $BIOS.Description)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Processors (Cores)"
$wsheet.Cells.Item($iRow,2) = $ComputerSystem.NumberOfProcessors
$iRow++
$wsheet.Cells.Item($iRow,1) = "CPU #"
$wsheet.Cells.Item($iRow,2) = "Type"
$wsheet.Cells.Item($iRow,3) = "Clock Speed"
$wsheet.Cells.Item($iRow,4) = "Bus Speed (Mhz)"
$iRow++
#Write-Output $ComputerSystem.NumberOfProcessors $Processors.Count
foreach($cpu in $Processors)
{
$wsheet.Cells.Item($iRow,1) = $cpu.DeviceID
$wsheet.Cells.Item($iRow,2) = $cpu.Name
$wsheet.Cells.Item($iRow,3) = $cpu.MaxClockSpeed
$wsheet.Cells.Item($iRow,4) = $cpu.ExtClock
$iRow++
}
$iRow++
$wsheet.Cells.Item($iRow,1) = "Memory Modules"
$wsheet.Cells.Item($iRow,2) = [string]::Format("{0}, (Total Physical Memory: {1}GB)", $Memory.Count, [math]::Round(($ComputerSystem.TotalPhysicalMemory/1GB), 2))
$iRow++
$wsheet.Cells.Item($iRow,1) = "Slot"
$wsheet.Cells.Item($iRow,2) = "Size (GB)"
$wsheet.Cells.Item($iRow,3) = "Speed"
$wsheet.Cells.Item($iRow,4) = "Manufacturer"
$wsheet.Cells.Item($iRow,5) = "PartNumber"
$wsheet.Cells.Item($iRow,6) = "SerialNumber"
$iRow++
foreach($memoryModule in $Memory)
{
$wsheet.Cells.Item($iRow,1) = $memoryModule.DeviceLocator #slot
$memoryType = $null
switch ($memoryModule.MemoryType)
{
"0" { $memoryType = "Unknown"; break }
"1" { $memoryType = "Other"; break }
"2" { $memoryType = "DRAM"; break }
"3" { $memoryType = "Synchronous DRAM"; break }
"4" { $memoryType = "Cache DRAM"; break }
"5" { $memoryType = "EDO"; break }
"6" { $memoryType = "EDRAM"; break }
"7" { $memoryType = "VRAM"; break }
"8" { $memoryType = "SRAM"; break }
"9" { $memoryType = "RAM"; break }
"10" { $memoryType = "ROM"; break }
"11" { $memoryType = "Flash"; break }
"12" { $memoryType = "EEPROM"; break }
"13" { $memoryType = "FEPROM"; break }
"14" { $memoryType = "EPROM"; break }
"15" { $memoryType = "CDRAM"; break }
"16" { $memoryType = "3DRAM"; break }
"17" { $memoryType = "SDRAM"; break }
"18" { $memoryType = "SGRAM"; break }
"19" { $memoryType = "RDRAM"; break }
"20" { $memoryType = "DDR"; break }
"21" { $memoryType = "DDR-2"; break }
"22" { $memoryType = "DDR-3"; break }
default { $memoryType = "Unavailable"; break }
}
$memoryFormFactor = $null
switch ($memoryModule.FormFactor)
{
"0" { $memoryFormFactor = "Unknown"; break }
"1" { $memoryFormFactor = "Other"; break }
"2" { $memoryFormFactor = "SIP"; break }
"3" { $memoryFormFactor = "DIP"; break }
"4" { $memoryFormFactor = "ZIP"; break }
"5" { $memoryFormFactor = "SOJ"; break }
"6" { $memoryFormFactor = "Proprietary"; break }
"7" { $memoryFormFactor = "SIMM"; break }
"8" { $memoryFormFactor = "DIMM"; break }
"9" { $memoryFormFactor = "TSOP"; break }
"10" { $memoryFormFactor = "PGA"; break }
"11" { $memoryFormFactor = "RIMM"; break }
"12" { $memoryFormFactor = "SODIMM"; break }
"13" { $memoryFormFactor = "SRIMM"; break }
"14" { $memoryFormFactor = "SMD"; break }
"15" { $memoryFormFactor = "SSMP"; break }
"16" { $memoryFormFactor = "WFP"; break }
"17" { $memoryFormFactor = "TQFP"; break }
"18" { $memoryFormFactor = "SOIC"; break }
"19" { $memoryFormFactor = "LCC"; break }
"20" { $memoryFormFactor = "PLCC"; break }
"21" { $memoryFormFactor = "BGA"; break }
"22" { $memoryFormFactor = "FPBGA"; break }
"23" { $memoryFormFactor = "LGA"; break }
default { $memoryFormFactor = [string]::Format("[Unknown FormFactor {0}]", $memoryModule.FormFactor); break }
}
$memoryPhysicalType = $null
switch ($memoryModule.TypeDetail)
{
"1" { $memoryPhysicalType = "Reserved"; break }
"2" { $memoryPhysicalType = "Other"; break }
"4" { $memoryPhysicalType = "Unknown"; break }
"8" { $memoryPhysicalType = "Fast-paged"; break }
"16" { $memoryPhysicalType = "Static column"; break }
"32" { $memoryPhysicalType = "Pseudo-static"; break }
"64" { $memoryPhysicalType = "RAMBUS"; break }
"128" { $memoryPhysicalType = "Synchronous"; break }
"256" { $memoryPhysicalType = "CMOS"; break }
"512" { $memoryPhysicalType = "EDO"; break }
"1024" { $memoryPhysicalType = "Window DRAM"; break }
"2048" { $memoryPhysicalType = "Cache DRAM"; break }
"4096" { $memoryPhysicalType = "Nonvolatile"; break }
default { $memoryPhysicalType = [string]::Format("[Unknown Type {0}]", $memoryModule.TypeDetail); break }
}
$wsheet.Cells.Item($iRow,2) = [string]::Format("Tag: {0} - FormFactor:{1}, Type: {2} {3}, Size: {4}GB", $memoryModule.Tag, $memoryFormFactor, $memoryType, $memoryPhysicalType, ($memoryModule.Capacity/1GB)) #size
$wsheet.Cells.Item($iRow,3) = $memoryModule.Speed
$wsheet.Cells.Item($iRow,4) = $memoryModule.Manufacturer
$wsheet.Cells.Item($iRow,5) = $memoryModule.PartNumber
$wsheet.Cells.Item($iRow,6) = $memoryModule.SerialNumber
$iRow++
}
$iRow++
$wsheet.Cells.Item($iRow,1) = "Registered User"
$wsheet.Cells.Item($iRow,2) = $($ComputerSystem.PrimaryOwnerName) # Registered User
$iRow++
$wsheet.Cells.Item($iRow,1) = "Organization"
$wsheet.Cells.Item($iRow,2) = $($OperatingSystems.Organization) # Registered Organization
$iRow++
$wsheet.Cells.Item($iRow,1) = "Last Booted"
$wsheet.Cells.Item($iRow,2) = $OperatingSystems.ConvertToDateTime($OperatingSystems.Lastbootuptime) # Last System Boot
$iRow++
$wsheet.Cells.Item($iRow,1) = "Time Zone"
$wsheet.Cells.Item($iRow,2) = $TimeZone.StandardName
$iRow = $iRow + 2
#region Logical Disk Configuration
Write-Output "..Logical Disks"
$wsheet.Cells.Item($iRow,1) = "Logical Disk Configuration"
$iRow++
$colDisks = Get-WmiObject -ComputerName $Target -Class Win32_LogicalDisk -Filter "DriveType=3" -Credential $Credentials
foreach ($objDisk in $colDisks)
{
$wsheet.Cells.Item($iRow,1) = $($objDisk.DeviceID) #Drive Letter
$wsheet.Cells.Item($iRow,2) = $($objDisk.VolumeName) #Label
$wsheet.Cells.Item($iRow,3) = $($objDisk.FileSystem)
$wsheet.Cells.Item($iRow,4) = $($objDisk.Size/1GB)
$wsheet.Cells.Item($iRow,4) = $($objDisk.FreeSpace/1GB)
$iRow++
}
$iRow = $iRow + 2
#endregion
$iRow++
#region Local Administrators
Write-Output "..Administrators"
$wsheet.Cells.Item($iRow,1) = "Administrators"
$iRow++
$computer = [ADSI]("WinNT://" + $Target + ",computer")
$Group = $computer.psbase.children.find("Administrators")
$members = $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
foreach($user in $members)
{
$wsheet.Cells.Item($iRow,1) = $user
$iRow++
}
$iRow++
#endregion
#UNCOMMENT THE FOLLOWING TO MAKE THE REPORT LESS VERBOSE
#$wsheetCount++
#$wsheet.UsedRange.EntireColumn.AutoFit()
#$wsheet.UsedRange.EntireColumn.AutoFilter()
#continue;
#region IIS (Web)
Write-Output "..IIS Configuration"
$wsheet.Cells.Item($iRow,1) = "IIS Configuration"
$iRow++
$wsheet.Cells.Item($iRow,1) = "Site Id"
$wsheet.Cells.Item($iRow,2) = "Log File Folder"
$wsheet.Cells.Item($iRow,3) = "Server Comment"
$wsheet.Cells.Item($iRow,4) = "Hostname"
$wsheet.Cells.Item($iRow,5) = "Site IP"
$wsheet.Cells.Item($iRow,6) = "Port"
$wsheet.Cells.Item($iRow,7) = "App Pool Id"
$iRow++
if ($OperatingSystems.Version.IndexOf("6.1") -gt -1)
{
# assume iis7
$iisServer = Get-WmiObject -namespace "root\WebAdministration" -ComputerName $Target -Authentication PacketPrivacy -Credential $Credentials -Class Site
if ($? -eq $false)
{
Write-Output " Error contacting IIS on {$Target}: $Error"
$Error.Clear() #keep it from appending to the stack
continue
}
if ($iisServer -ne $null)
{
foreach($site in $iisServer)
{
$wsheet.Cells.Item($iRow,1) = $site.Id
$wsheet.Cells.Item($iRow,2) = $site.LogFile.Directory
$wsheet.Cells.Item($iRow,3) = $null #comment
$wsheet.Cells.Item($iRow,4) = $site.Name
$wsheet.Cells.Item($iRow,7) = $site.ApplicationDefaults.ApplicationPool
foreach($binding in $site.Bindings)
{
$wsheet.Cells.Item($iRow,5) = $binding.BindingInformation
$wsheet.Cells.Item($iRow,6) = $binding.Protocol
$iRow++
}
$iRow++
}
}
}
else
{
#iis6
$iisInfo = Get-WMIObject -namespace "root\microsoftiisv2" -ComputerName $Target -authentication PacketPrivacy -Credential $Credentials -Query 'select * from IIsWebServerSetting'
if ($iisInfo -ne $null)
{
foreach($syncroot in $iisInfo)
{
#Write-Output $syncroot.Name $syncroot.ServerComment $syncroot.LogFileDirectory $syncroot.AppPoolId
$wsheet.Cells.Item($iRow,1) = $syncroot.Name
$wsheet.Cells.Item($iRow,2) = $syncroot.LogFileDirectory
$wsheet.Cells.Item($iRow,3) = $syncroot.ServerComment
$wsheet.Cells.Item($iRow,7) = $syncroot.AppPoolId
foreach($binding in $syncroot.ServerBindings)
{
#Write-Output $binding.Hostname $binding.IP $binding.Port
$wsheet.Cells.Item($iRow,4) = $binding.Hostname
$wsheet.Cells.Item($iRow,5) = $binding.IP
$wsheet.Cells.Item($iRow,6) = $binding.Port
$iRow++
}
$iRow++
}
}
}
$iRow++
#endregion
#region ArcGIS
# Write-Output "..ArcGIS"
# $ArcGisServices = Get-WmiObject -ComputerName $Target -Credential $Credentials -Class "Win32_Service" -Filter "DisplayName like 'ArcSde%'"
# if ($ArcGisServices -ne $null)
# {
# $wsheet.Cells.Item($iRow,1) = "ArcGIS"
# $iRow++
#
# $wsheet.Cells.Item($iRow,1) = "DisplayName"
# $wsheet.Cells.Item($iRow,2) = "Name"
# $wsheet.Cells.Item($iRow,3) = "Startup"
# $wsheet.Cells.item($iRow,4) = "Status"
# $iRow++
#
# foreach ($arcGisSvc in $ArcGisServices)
# {
# $wsheet.Cells.Item($iRow,1) = $arcGisSvc.DisplayName
# $wsheet.Cells.Item($iRow,2) = $arcGisSvc.Name
# $wsheet.Cells.Item($iRow,3) = $arcGisSvc.StartMode
# $wsheet.Cells.item($iRow,4) = $arcGisSvc.Status
# # write-host $arcGisSvc.InstallDate $arcGisSvc.DisplayName $arcGisSvc.Caption $arcGisSvc.Name $arcGisSvc.Properties
# $iRow++
# }
#
# $iRow++
# }
#endregion
#region Oracle
# Write-Output "..Oracle"
# $OracleServices = Get-WmiObject -ComputerName $Target -Credential $Credentials -Class "Win32_Service" -Filter "DisplayName like 'Oracle%'"
# if ($OracleServices -ne $null)
# {
# $wsheet.Cells.Item($iRow,1) = "Oracle"
# $iRow++
#
# $wsheet.Cells.Item($iRow,1) = "DisplayName"
# $wsheet.Cells.Item($iRow,2) = "Name"
# $wsheet.Cells.Item($iRow,3) = "Startup"
# $wsheet.Cells.item($iRow,4) = "Status"
# $iRow++
#
# foreach ($oracleSvc in $OracleServices)
# {
# #write-host $oracleSvc.InstallDate $oracleSvc.DisplayName $oracleSvc.Caption $oracleSvc.Name
# $wsheet.Cells.Item($iRow,1) = $oracleSvc.DisplayName
# $wsheet.Cells.Item($iRow,2) = $arcGisSvc.Name
# $wsheet.Cells.Item($iRow,3) = $oracleSvc.StartMode
# $wsheet.Cells.item($iRow,4) = $oracleSvc.State
# $iRow++
# }
#
# $iRow++
# }
#endregion
#region MS SQL Server
Write-Output "..MS SQL"
$IsMsSqlServer = $false
$IsMsSql2005 = $false
$IsMsSql2008 = $false
if(Get-WmiObject -ComputerName $Target -Credential $Credentials -Namespace root\Microsoft\SQLServer\ComputerManagement -Class SqlServiceAdvancedProperty -ErrorAction SilentlyContinue )
{
$IsMsSqlServer = $true
$IsMsSql2005 = $true
$Version2005 = Get-WmiObject -ComputerName $Target -Credential $Credentials -Namespace root\Microsoft\SQLServer\ComputerManagement -Class SqlServiceAdvancedProperty | where {$_.SqlServiceType -eq 1 -and $_.PropertyName -eq "VERSION"} #| select Servicename, Propertystrvalue | ft -AutoSize
}
if (Get-WmiObject -ComputerName $Target -Credential $Credentials -Namespace root\Microsoft\SQLServer\ComputerManagement10 -Class SqlServiceAdvancedProperty -ErrorAction SilentlyContinue)
{
$IsMsSqlServer = $true
$IsMsSql2008 = $true
$Version2008 = Get-WmiObject -ComputerName $Target -Credential $Credentials -Namespace root\Microsoft\SQLServer\ComputerManagement10 -Class SqlServiceAdvancedProperty | where {$_.SqlServiceType -eq 1 -and $_.PropertyName -eq "VERSION"} #| select Servicename, Propertystrvalue | ft -AutoSize
}
if ($IsMsSqlServer)
{
$wsheet.Cells.Item($iRow,1) = "Database"
$iRow++
$wsheet.Cells.Item($iRow,1) = "Type"
$wsheet.Cells.Item($iRow,2) = "Version"
$wsheet.Cells.Item($iRow,3) = "Instance Name"
$iRow++
if ($IsMsSql2005)
{
$wsheet.Cells.Item($iRow,1) = "MS SQL 2005"
$wsheet.Cells.Item($iRow,2) = $version2005.PropertyStrValue
$wsheet.Cells.Item($iRow,3) = $version2005.ServiceName
$iRow++
}
if ($IsMsSql2008)
{
$wsheet.Cells.Item($iRow,1) = "MS SQL 2008 (or higher)"
$wsheet.Cells.Item($iRow,2) = $version2008.PropertyStrValue
$wsheet.Cells.Item($iRow,3) = $version2008.ServiceName
$iRow++
}
$iRow++
}
#endregion
#region NIC Configuration
Write-Output "..Network Configuration"
$wsheet.Cells.Item($iRow,1) = "Network Configuration"
$iRow++
$colAdapters = Get-WmiObject -ComputerName $Target -Class Win32_NetworkAdapterConfiguration -Credential $Credentials | Where{$_.IpEnabled -Match "True"}
$wsheet.Cells.Item($iRow,1) = "Enabled NICs"
if ($colAdapters.Length -ne $null)
{
$wsheet.Cells.Item($iRow,2) = $($colAdapters.Count)
}
else
{
$wsheet.Cells.Item($iRow,2) = 1
}
foreach ($objAdapter in $colAdapters)
{
$wsheet.Cells.Item($iRow,1) = "Description"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.Description)
$iRow++
$wsheet.Cells.Item($iRow,1) = "MAC Address"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.MACaddress) #Physical address
$iRow++
$wsheet.Cells.Item($iRow,1) = "IP Address"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.IPAddress) #IP Address / Subnet Mask
$iRow++
$wsheet.Cells.Item($iRow,1) = "Subnet"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.IPSubnet)
$iRow++
$wsheet.Cells.Item($iRow,1) = "Gateway"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.DefaultIPGateway) #Default Gateway
$iRow++
$wsheet.Cells.Item($iRow,1) = "DHCP"
$wsheet.Cells.Item($iRow,2) = ($objAdapter.DHCPEnabled -eq "True") #DHCP enabled
$iRow++
#DNS Servers
$wsheet.Cells.Item($iRow,1) = "DNS"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.DNSServerSearchOrder)
$iRow++
#Primary WINS Server
$wsheet.Cells.Item($iRow,1) = "Primary WINS"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.WINSPrimaryServer)
$iRow++
#Secondary WINS Server
$wsheet.Cells.Item($iRow,1) = "Secondary WINS"
$wsheet.Cells.Item($iRow,2) = $($objAdapter.WINSSecondaryServer)
$iRow++
#row spacer
$iRow++
}
$iRow = $iRow + 2
#endregion
#region Local Shares
Write-Output "..Local Shares"
$wsheet.Cells.Item($iRow,1) = "Server Shares"
$iRow++
$wsheet.Cells.Item($iRow,1) = "Share Name"
$wsheet.Cells.Item($iRow,2) = "Physical Path"
$wsheet.Cells.Item($iRow,3) = "Comment"
$iRow++
$colShares = Get-wmiobject -ComputerName $Target -Class Win32_Share -Credential $Credentials
Foreach ($objShare in $colShares)
{
$wsheet.Cells.Item($iRow,1) = $($objShare.Name) #Share Name
$wsheet.Cells.Item($iRow,2) = $($objShare.Path)
$wsheet.Cells.Item($iRow,3) = $($objShare.Caption) #Comment
$iRow++
#Write-Output $($objShare.Name) #Share Name
#Write-Output $($objShare.Path) #Path
#Write-Output $($objShare.Caption) #Comment
}
$iRow = $iRow + 2
#endregion
#region Installed Software
# Write-Output "..Installed Software"
# $wsheet.Cells.Item($iRow, 1) = "Installed Software"
# $iRow++
#
# $wsheet.Cells.Item($iRow, 1) = "Name"
# $wsheet.Cells.Item($iRow, 2) = "Version"
# $wsheet.Cells.Item($iRow, 3) = "Vendor"
# $wsheet.Cells.Item($iRow, 4) = "Install Date"
#
# $colApps = Get-wmiobject -ComputerName $Target -Class Win32_Product -Credential $Credentials | select Name,Version,Vendor,InstallDate
# foreach ($objApps in $colApps)
# {
# $wsheet.Cells.Item($iRow,1) = $($objApps.Name)
# $wsheet.Cells.Item($iRow,2) = $($objApps.Version)
# $wsheet.Cells.Item($iRow,3) = $($objApps.Vendor)
# $wsheet.Cells.Item($iRow,4) = $($objApps.InstallDate)
# $iRow++
# }
# $iRow = $iRow + 2
#endregion
#region HOTFIXES
# Write-Output "..Hotfix Information"
# $wsheet.Cells.Item($iRow,1) = "Hotfix Information"
# $iRow++
#
# $colQuickFixes = Get-WmiObject Win32_QuickFixEngineering
# ForEach ($objQuickFix in $colQuickFixes)
# {
# if ($objQuickFix.HotFixID -eq "File 1")
# {
# $wsheet.Cells.Item($iRow,1) = $objQuickFix.ServicePackInEffect
# }
# else
# {
# $wsheet.Cells.Item($iRow,1) = $objQuickFix.HotFixID #HotFix Number
# }
#
# if ($objQuickFix.HotFixID -ne $null)
# {
# $wsheet.Cells.Item($iRow,2) = $objQuickFix.Description
# }
# if ($objQuickFix.HotFixID -ne $null)
# {
# $wsheet.Cells.Item($iRow,3) = $objQuickFix.InstalledBy
# }
# if ($objQuickFix.HotFixID -ne $null)
# {
# $wsheet.Cells.Item($iRow,4) = $objQuickFix.InstalledOn
# }
# if ($objQuickFix.HotFixID -ne $null)
# {
# $wsheet.Cells.Item($iRow,5) = $objQuickFix.InstallDate
# }
# $iRow++
# }
# $iRow = $iRow + 2
#endregion
#region Printers
# Write-Output "..Printers"
# $colInstalledPrinters = Get-WmiObject -ComputerName $Target Win32_Printer -Credential $Credentials
# Foreach ($objPrinter in $colInstalledPrinters)
# {
# If ($objPrinter.Name -eq "")
# {
# #No Printers Installed
# }
# Else
# {
# $($objPrinter.Name)
# $($objPrinter.Location)
# if ($objPrinter.Default -eq "True")
# {
#
# }
# Else
# {
#
# }
# $($objPrinter.Portname)
# }
# }
#endregion
#region ALL Services
# Write-Output "..Services"
# $wsheet.Cells.Item($iRow,1) = "Services"
# $iRow++
#
# $wsheet.Cells.Item($iRow,1) = "Name"
# $wsheet.Cells.Item($iRow,2) = "Log On As"
# $wsheet.Cells.Item($iRow,3) = "Startup Type"
# $wsheet.Cells.Item($iRow,4) = "Status"
# $iRow++
#
# $colListOfServices = Get-WmiObject -ComputerName $Target Win32_Service -Credential $Credentials |Sort-Object -property Caption
# Foreach ($objService in $colListOfServices)
# {
# $wsheet.Cells.Item($iRow,1) = $($objService.Caption)
# $wsheet.Cells.Item($iRow,2) = $($objService.StartName)
# $wsheet.Cells.Item($iRow,3) = $($objService.StartMode)
# $wsheet.Cells.Item($iRow,4) = $($objService.State)
# $iRow++
#
# #Write-Output $($objService.Caption) $($objService.StartName) $($objService.StartMode) $($objService.State)
#
# If ($objService.StartMode -eq "Auto")
# {
# switch ($objService.State)
# {
# "Stopped"
# {
# break
# }
# "Running"
# {
# break
# }
# }
#
# }
#
# If ($objService.StartMode -eq "Disabled")
# {
# switch ($objService.State)
# {
# "Running"
# {
# break
# }
# "Stopped"
# {
# break
# }
# }
# }
#
# If ($objService.StartMode -eq "Manual")
# {
# #switch ($objService.State)
# #{
# # $($objService.State)
# #}
# }
#
# If ($objService.State -eq "Paused")
# {
# #switch ($objService.State)
# #{
# # $($objService.State)
# #}
# }
# } #/ForEach
# $iRow = $iRow + 2
#endregion
#region Regional Settings
# Write-Output "..Regional Options"
# $ObjKeyboards = Get-WmiObject -ComputerName $Target Win32_Keyboard -Credential $Credentials
# $keyboardmap = @{
# "00000402" = "BG"
# "00000404" = "CH"
# "00000405" = "CZ"
# "00000406" = "DK"
# "00000407" = "GR"
# "00000408" = "GK"
# "00000409" = "US"
# "0000040A" = "SP"
# "0000040B" = "SU"
# "0000040C" = "FR"
# "0000040E" = "HU"
# "0000040F" = "IS"
# "00000410" = "IT"
# "00000411" = "JP"
# "00000412" = "KO"
# "00000413" = "NL"
# "00000414" = "NO"
# "00000415" = "PL"
# "00000416" = "BR"
# "00000418" = "RO"
# "00000419" = "RU"
# "0000041A" = "YU"
# "0000041B" = "SL"
# "0000041C" = "US"
# "0000041D" = "SV"
# "0000041F" = "TR"
# "00000422" = "US"
# "00000423" = "US"
# "00000424" = "YU"
# "00000425" = "ET"
# "00000426" = "US"
# "00000427" = "US"
# "00000804" = "CH"
# "00000809" = "UK"
# "0000080A" = "LA"
# "0000080C" = "BE"
# "00000813" = "BE"
# "00000816" = "PO"
# "00000C0C" = "CF"
# "00000C1A" = "US"
# "00001009" = "US"
# "0000100C" = "SF"
# "00001809" = "US"
# "00010402" = "US"
# "00010405" = "CZ"
# "00010407" = "GR"
# "00010408" = "GK"
# "00010409" = "DV"
# "0001040A" = "SP"
# "0001040E" = "HU"
# "00010410" = "IT"
# "00010415" = "PL"
# "00010419" = "RU"
# "0001041B" = "SL"
# "0001041F" = "TR"
# "00010426" = "US"
# "00010C0C" = "CF"
# "00010C1A" = "US"
# "00020408" = "GK"
# "00020409" = "US"
# "00030409" = "USL"
# "00040409" = "USR"
# "00050408" = "GK"
# }
#
# $keyb = $keyboardmap.$($ObjKeyboards.Layout)
# if (!$keyb)
# {
# $keyb = "Unknown"
# }
# $($TimeZone.Description)
# $($OperatingSystems.Countrycode)
# $($OperatingSystems.Locale)
# $($OperatingSystems.OSLanguage)
# $keyb #Keyboard Layout
#endregion
# Write-Output "..Event Log Settings"
# $colLogFiles = Get-WmiObject -ComputerName $Target Win32_NTEventLogFile -Credential $Credentials
# Write-Output "..Event Log Errors"
# $WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-14))
# $colLoggedEvents = Get-WmiObject -computer $Target -query ("Select * from Win32_NTLogEvent Where Type='Error' and TimeWritten >='" + $WmidtQueryDT + "'") -Credential $Credentials
# Write-Output "..Event Log Warnings"
# $WmidtQueryDT = [System.Management.ManagementDateTimeConverter]::ToDmtfDateTime([DateTime]::Now.AddDays(-14))
# $colLoggedEvents = Get-WmiObject -computer $Target -query ("Select * from Win32_NTLogEvent Where Type='Warning' and TimeWritten >='" + $WmidtQueryDT + "'") -Credential $Credentials
#region Event Logs
#region Eventlog settings
# ForEach ($objLogFile in $colLogfiles)
# {
# If ($objLogfile.OverWriteOutdated -lt 0)
# {
# #Never
# }
# if ($objLogFile.OverWriteOutdated -eq 0)
# {
# #As needed
# }
# Else
# {
# #After $($objLogFile.OverWriteOutdated) days
# }
# $MaxFileSize = ($objLogfile.MaxFileSize) / 1024
# $FileSize = ($objLogfile.FileSize) / 1024
# }
#endregion
#region ERROR Entries
# ForEach ($objEvent in $colLoggedEvents)
# {
# $ObjEvent.ConvertToDateTime($objEvent.TimeWritten)
# $($objEvent.EventCode)
# $($objEvent.SourceName)
# $dtmEventDate
# $($objEvent.LogFile)
# $($objEvent.Message)
# }
#endregion
#region WARNING Entries
# ForEach ($objEvent in $colLoggedEvents)
# {
# $StrWMIDate = $ObjEvent.ConvertToDateTime($objEvent.TimeWritten)
# $($objEvent.EventCode)
# $($objEvent.SourceName)
# $($dtmEventDate)
# $($objEvent.LogFile)
# $($objEvent.Message)
# }
#endregion
#endregion
$range = $wsheet.UsedRange
$range.EntireColumn.AutoFilter()
$range.EntireColumn.AutoFit()
$iRow++
$wsheetCount++
} #/ForEach
#PDF option
#$xlFixedFormat = "Microsoft.Office.Interop.Excel.xlFixedFormatType" -as [type]
#$excel.ActiveWorkbook.ExportAsFixedFormat($xlFixedFormat::xlTypePDF, $SaveFilename +".pdf")
$excel.ActiveWorkbook.SaveAs($SaveFilename)
$excel.ActiveWorkbook.Close()
$excel.Application.Quit()
If (Get-Process excel)
{
Stop-Process -Name excel
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment