Windows Server System Report WMI, MAC, IPADDRESS, Disk Usauge, Certificate Expiration, etc
Windows Server System Report WMI, MAC, IPADDRESS, Disk Usauge, Certificate Expiration, etc
I'll hafta write more here later to help google get the keywords it need on this
This script gets almost everything you could want to know about the windows machine is queries.
The script returns:
Name,HyperHostName,Domain,Manufacturer,Model,SerialNum,Installdate,Memory,CpuSpeed,ProcessorCount,ProcessorCores,LogicalProcessorCount,OS,OSVersion,
OSServicePack,OSBitLevel,NORESPONSE,Uptime,DhcpEnabled,Speed,IpAddress,IpSubnet,IpGateway,DNSServerSearchOrder,DNSDomainSuffixSearchOrder,
MacAddress,DriveName,drivefilesystem,drivequota,driveused,drivefreespace,drivesize,NumberofCerts,NameOfCerts,ExpiringCerts,Certexpires
#requires the network adapter to be configure with the dns of all the servers it will be calling ie domain1.com,otherdomain.com
Add-PSSnapin Quest.Activeroles.ADManagement
#files
$webfile = "c:\svr\www\printers\index.php"
clear
$WebpageOutputEnabled = $true
$myservers = @()
$myreport = @()
$myservers = ("dhcpserver.domain1.com","domaincontroller.domain1.com","exchangeserver.otherdomain.com","hyperhostetc.otherdomain.com")
function do_mail ($myhtml) {
$mymail = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient("mailrelay.domain1.com") #Dns name or IP
$mymail.IsBodyHTML = $true
$mymail.From = "ServerReporting@Company.edu"
$mymail.To.Add("sysadmins@company.edu")
$mymail.Subject = ("Server extended information report")
$mymail.Body = $myhtml
#$mymail.Attachments.Add($attach)
$smtp.Send($mymail)
} #do_mail
#flip between using a AD query for all servers under a container, to the $myservers list above by changing commented foreach loop
Foreach ( $curserver in (Get-QADComputer -SearchRoot "OU=Domain Servers,DC=Ourcompany,DC=com") ) {#foreach1 prod
#Foreach ( $server in $myservers ) {#foreach1 testing
$server = $curserver.dnsname
if (Test-Connection -cn $server -Quiet -Count 1) {#ifconnect
# wmi hint $this | foreach { $_.PSObject.Properties | select name,value }
$this = Get-WmiObject -class win32_OperatingSystem -cn $server
$thiscpu = Get-WmiObject -class win32_Processor -cn $server
$thisdisk = Get-WmiObject -class win32_Logicaldisk -cn $server
$thishw = Get-WmiObject -class Win32_ComputerSystem -cn $server
$thisnw = Get-WmiObject -class Win32_NetworkAdapter -cn $server
$thisbios = Get-WmiObject -class Win32_bios -cn $server
$thisnw2 = Get-WmiObject -class Win32_NetworkAdapterConfiguration -cn $server
## Get Vm-Host Information
if ($thishw.Model -eq "Virtual Machine") {#ifvmmachine
$VmHostName = invoke-command { (Get-Item "HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters").GetValue("HostName") } -computername $server
}#ifvmmachine
Else {
$VmHostName = "HardWare"
}
## End Get Vm-Host Information
#Set Script Variables
$obj = $null
$obj = "" | select Name,HyperHostName,Domain,Manufacturer,Model,SerialNum,Installdate,Memory,CpuSpeed,ProcessorCount,ProcessorCores,LogicalProcessorCount,OS,OSVersion,OSServicePack,OSBitLevel,NORESPONSE,Uptime,DhcpEnabled,Speed,IpAddress,IpSubnet,IpGateway,DNSServerSearchOrder,DNSDomainSuffixSearchOrder,MacAddress,DriveName,drivefilesystem,drivequota,driveused,drivefreespace,drivesize,NumberofCerts,NameOfCerts,ExpiringCerts,Certexpires
$obj.Name = $thishw.Name
$obj.HyperHostName = $VmHostName
#$obj.DNSName = $thishw.DNSHostName
$obj.Domain = $thishw.Domain
#$obj.Description = $this.Description
$obj.Manufacturer = $thishw.Manufacturer
$obj.Model = $thishw.Model
$obj.SerialNum = $thisbios.SerialNumber
$obj.Installdate = ($this.converttodatetime($this.installdate))
$obj.Memory = ([math]::truncate($thishw.TotalPhysicalMemory/1gb))
$obj.CpuSpeed = $thiscpu.MaxClockSpeed
$obj.ProcessorCount = $thishw.NumberOfProcessors
$obj.ProcessorCores = $thiscpu.NumberOfCores
$obj.LogicalProcessorCount = $thishw.NumberOfLogicalProcessors
$obj.OS = $this.Caption
$obj.OSVersion = $this.Version
$obj.OSServicePack = $this.CSDVersion
$obj.OSBitLevel = $this.OSArchitecture
$obj.NORESPONSE = "FALSE"
$obj.Uptime = ((get-date) - $this.converttodatetime($this.lastbootuptime))
##Network Only
$mynicpass = 1
$mytxtpass = 1
$addtxt = ""
foreach ( $nic in ($thisnw | where {$_.physicaladapter -eq $true } ))
{ #fornicpass1
$thisnic = $thisnw2 | where { $_.index -eq $nic.DeviceID }
if ( $thisnic.IPAddress -ne $null ) {#ifnicpass1
if ($mytxtpass -ne "1") { $addtxt = "," }
$dhcptext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.DHCPEnabled
$nicspeedtext += "" + $addtxt + "Nic"+ $mynicpass + ":" + ($nic.Speed/1000000)
$iptext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.IpAddress
$subnettext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.IPSubnet
$gatewaytext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.DefaultIPGateway
$dnstext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.DNSServerSearchOrder
$domaintext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.DNSDomainSuffixSearchOrder
$mactext += "" + $addtxt + "Nic"+ $mynicpass + ":" + $thisnic.MACAddress
$mytxtpass += 1
}#end ifnicpass1 $nic.Speed/1000000
$mynicpass += 1
}#end fornicpass1
$obj.DhcpEnabled = $dhcptext
$obj.Speed = $nicspeedtext
$obj.IpAddress = $iptext
$obj.IpSubnet = $subnettext
$obj.IpGateway = $gatewaytext
$obj.DNSServerSearchOrder = $dnstext
$obj.DNSDomainSuffixSearchOrder = $domaintext
$obj.MacAddress = $mactext
#cleanup
$iptext = $null
$mactext = $null
$subnettext = $null
$dhcptext = $null
$gatewaytext = $null
$dnstext = $null
$domaintext = $null
$nicspeedtext = $null
## End Network
## start disk
$mytxtpass = 1
$addtxt = ""
foreach ( $drive in ($thisdisk | where {$_.Description -eq "Local Fixed Disk" } ))
{ #forhdpass1
if ($mytxtpass -ne "1") { $addtxt = "," }
$drivenametext += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + $drive.VolumeName
$drivefilesystemtext += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + $drive.filesystem
$drivequotatext += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + $drive.quotasdisabled
$driveusedtext += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + ([math]::truncate(($drive.size - $drive.freespace)/1gb))
$drivefreespace += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + ([math]::truncate($drive.freespace/1gb))
$drivesize += "" + $addtxt + "Drive["+ $drive.DeviceID + "]:" + ([math]::truncate($drive.size/1gb))
$mytxtpass += 1
}#end forhdpass1
$obj.DriveName = $drivenametext
$obj.drivefilesystem = $drivefilesystemtext
$obj.drivequota = $drivequotatext
$obj.driveused = $driveusedtext
$obj.drivefreespace = $drivefreespace
$obj.drivesize = $drivesize
#cleanup
$drivenametext = $null
$drivefilesystemtext = $null
$drivequotatext = $null
$driveusedtext = $null
$drivefreespace = $null
$drivesize = $null
## End Disk
## Certificates
$mycertpass = 0
$mytxtpass = 1
$addtxt = ""
$certs = invoke-command {gci cert:\LocalMachine\My } -computername $server
foreach ( $cert in ($certs | where { $_.Issuer -ne "CN=youlocaldomain-CA, DC=youdomain, DC=com" }))
{ #forcertpass1
if ($mytxtpass -ne "1") { $addtxt = "," }
$certnametext += "" + $addtxt + "Cert ["+ $mytxtpass + "]:" + $cert.Subject.Split(",")[0]
$certexpirestext += "" + $addtxt + "Cert ["+ $mytxtpass + "]:" + $cert.NotAfter
if ($cert.NotAfter -ile ((get-date).AddDays.(30))) {
$Certexpiredtext += "" + $addtxt + "Cert ["+ $mytxtpass + "]:TRUE"
} else {
$Certexpiredtext += "" + $addtxt + "Cert ["+ $mytxtpass + "]:FALSE"
}
$mytxtpass += 1
$mycertpass += 1
}#end forcertpass1
$obj.NumberofCerts = $mycertpass
$obj.NameOfCerts = $certnametext
$obj.ExpiringCerts = $Certexpiredtext
$obj.Certexpires = $certexpirestext
#cleanup
$mycertpass = $null
$Certexpiredtext = $null
$drivequotatext = $null
$certnametext = $null
$certexpirestext = $null
## End Certificates
## add to report
$myreport += $obj
#cleanup
$nic = $null
$drive = $null
$cert = $null
$VmHostName = $null
}#ifconnect
ELSE {#elseifconnect
$obj = $null
$obj = "" | select Name,HyperHostName,Domain,Manufacturer,Model,SerialNum,Installdate,Memory,CpuSpeed,ProcessorCount,ProcessorCores,LogicalProcessorCount,OS,OSVersion,OSServicePack,OSBitLevel,NORESPONSE,Uptime,DhcpEnabled,Speed,IpAddress,IpSubnet,IpGateway,DNSServerSearchOrder,DNSDomainSuffixSearchOrder,MacAddress,DriveName,drivefilesystem,drivequota,driveused,drivefreespace,drivesize,NumberofCerts,NameOfCerts,ExpiringCerts,Certexpires
$obj.Name = $server
$obj.HyperHostName = "NA"
$obj.NORESPONSE = "TRUE"
$myreport += $obj
}#elseifconnect
}#foreach1
if ($WebpageOutputEnabled) {#WebEnabled
#exporttoweb
Remove-Item ($webfile)
$head = "<style>"
$head = $head + "BODY{background-color:#9FAEB5;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#999999}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#CCCCCC}"
$head = $head + "</style>"
if ((Test-Path -Path $webfile) -ne $true) {#writehead top
$myreport | sort-object -Property "HyperHostName" | ConvertTo-HTML -head $head -body ("<H2>" + $myreport.Count + "Server Information Site</H2>") | Out-File $webfile
} else {
$myreport | sort-object -Property "HyperHostName" | ConvertTo-HTML | Out-File $webfile -Append
}
}# WebEnabled
$myhtml = $myreport | sort-object -Property "HyperHostName" | ConvertTo-HTML -head $head -body ("<H2>" + $myreport.Count + "Server Information Site</H2>")
do_mail $myhtml