Hi All,
Hopefully someone can help me with this. I'm quite new to powershell and dont really know much about it. A bit of background on what i want to achieve.
At the end of each server build (vm or physical), I would like to run a script which does a full inventory of our windows servers and checks for anything which is not configured / installed. So for example once the server is build, I would like to check what windows features are installed / GPO's are applied / windows activation status etc and then i want the script to create a HTML report and highlight anything it finds which could be missing or not configured. I understand this is quite vague but for the time being i would just like a generic check and then can fine tune it later. I have managed to get the following script from another site and added a few modifications myself but need to now get it doing what i want:
Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue
$UserName = (Get-Item env:\username).Value
$ComputerName = (Get-Item env:\Computername).Value
#$filepath = (Get-ChildItem env:\userprofile).value
$share = "\\files\general$\Operations\Build Reports"
#ReportDate
$ReportDate = Get-Date | Select -Property DateTime |ConvertTo-Html -Fragment
#General Information
$ComputerSystem = Get-WmiObject -Class Win32_ComputerSystem |
Select -Property Model , Manufacturer , Description , PrimaryOwnerName , SystemType |ConvertTo-Html -Fragment
#Operating System Information
$OS = Get-WmiObject -Class Win32_OperatingSystem | Select -Property Caption , CSDVersion , OSArchitecture , OSLanguage | ConvertTo-Html -Fragment
#Windows Activation Status
$Activation = Get-CimInstance -ClassName SoftwareLicensingProduct | where PartialProductKey | Select Name, @{Label="Grace period (days)"; Expression={ $_.graceperiodremaining / 1440}}, @{Label= "License Status"; Expression={switch (foreach
{$_.LicenseStatus}) { 0 {"Unlicensed"} 1 {"Licensed"} 2 {"Out-Of-Box Grace Period"} 3 {"Out-Of-Tolerance Grace Period"} 4 {"Non-Genuine Grace Period"} 5 {"Notification Period"} 6 {"Extended Grace"}
} } } | ConvertTo-Html -Fragment
#Logical Disk Information
$Disk = Get-WmiObject -Class Win32_LogicalDisk -Filter DriveType=3 |
Select SystemName , DeviceID , @{Name=size(GB);Expression={{0:N1} -f($_.size/1gb)}}, @{Name=freespace(GB);Expression={{0:N1} -f($_.freespace/1gb)}} |
ConvertTo-Html -Fragment
#Time Zone Information
$TimeZone = Get-WmiObject -Class Win32_TimeZone | Select Caption , StandardName | ConvertTo-Html -Fragment
#CPU Information
$SystemProcessor = Get-WmiObject -Class Win32_Processor | Select SystemName , Name , MaxClockSpeed , Manufacturer , status |ConvertTo-Html -Fragment
#Memory Information
$PhysicalMemory = Get-WmiObject -Class Win32_PhysicalMemory | Select -Property Tag , SerialNumber , PartNumber , Manufacturer , DeviceLocator , @{Name="Capacity(GB)";Expression={"{0:N1}" -f ($_.Capacity/1GB)}} | ConvertTo-Html -Fragment
#Software Inventory
$Software = Get-WmiObject -Class Win32_Product | Select Name , Vendor , Version , Caption | ConvertTo-Html -Fragment
#Windows Features Inventory
$Features = Get-WmiObject -query "select * from win32_optionalfeature where installstate=1" | select Name, Caption | ConvertTo-Html -Fragment
ConvertTo-Html -Body "<font color = blue><H4><B>Report Executed On</B></H4></font>$ReportDate
<font color = blue><H4><B>Report Generated By</B></H4></font>$username
<font color = blue><H4><B>General Information</B></H4></font>$ComputerSystem
<font color = blue><H4><B>Operating System Information</B></H4></font>$OS
<font color = blue><H4><B>Activation Status</B></H4></font>$Activation
<font color = blue><H4><B>Time Zone Information</B></H4></font>$TimeZone
<font color = blue><H4><B>Disk Information</B></H4></font>$Disk
<font color = blue><H4><B>Processor Information</B></H4></font>$SystemProcessor
<font color = blue><H4><B>Memory Information</B></H4></font>$PhysicalMemory
<font color = blue><H4><B>Windows Features Iventory</B></H4></font>$Features
<font color = blue><H4><B>Software Inventory</B></H4></font>$Software" -CssUri "$share\style.CSS" -Title "Server Inventory" | Out-File "$share\$ComputerName.html"
Write-Host "Script Execution Completed" -ForegroundColor Yellow
Invoke-Item -Path "$share\$ComputerName.html"
So what I would like is in the HTML report, anything that is not done right is highlighted in Red with a quick sentence at the end stating the issue. So for example where this script checks the Windows Activation status, I would like that any status which is reported that is not "Licensed" is highlighted red in the HTML report and a sentence at the end of the report which reads out something like "Windows is not activated. Please activate". All our base build have a certain set of windows features installed, so the script could reference a set of features installed on a current system (possibly output the windows features from a correctly built system which is output to a file and then compared on the newly built server) and check what is missing and again highlight in red (for example "Failover clustering is not Installed" etc.
I would appreciate any help that could be provided
Thanks
- Edited by jutler123 Tuesday, August 19, 2014 3:21 PM


