Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write-Output " `n Start of Hal0 `n";
- #Start of Server Connection
- $connectionString = "Server=KINGDB01;Database=Hal0Test;Integrated Security=True;"
- $connection = New-Object System.Data.SqlClient.SqlConnection
- $connection.ConnectionString = $connectionString
- $connection.Open()
- $command = $connection.CreateCommand()
- $ServerArray = [System.Collections.ArrayList]@()
- $query = "SELECT ServerName FROM ServerList"
- $command.CommandText = $query
- $ServerNames = $command.ExecuteReader()
- $table = new-object “System.Data.DataTable”
- $table.Load($ServerNames)
- $ServerArray = $table | select -Expand ServerName
- #Start of HTML Code
- $Outputreport =
- "<HTML><TITLE> IDI Server Report </TITLE>
- <BODY background-color:peachpuff>
- <font color =""#99000"" face=""Microsoft Tai le"">
- <H2> IDI Server Report </H2></font>
- <Table border=1 cellpadding=0 cellspacing=0>
- <TR bgcolor=gray align=center>
- <TD><B>Server Name</B></TD>
- <TD><B>FQDN</B></TD>
- <TD><B>CPU Usage</B></TD>
- <TD><B>RAM Usage</B></TD>
- <TD><B>RAM Specs.</B></TD>
- <TD><B>Disk Space</B></TD>
- <TD><B>Operating System</B></TD></TR>"
- $ServerArray | ForEach-Object {
- # $ServerArray returns each server name
- # collection code re-inserted
- #Operating System
- $SystemInfo = Get-WmiObject -Class Win32_OperatingSystem -computername $_
- $os = Get-WmiObject -Class Win32_OperatingSystem -Computer $_
- #Server's Memory (RAM) Usage Average
- $memAvg = gwmi -Class win32_operatingsystem -computername $_ | Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
- #Server's CPU (Proccess) Usage Average
- $TotalRAM = [math]::round($SystemInfo.TotalVisibleMemorySize/1MB,4)
- $FreeRAM = [math]::round($SystemInfo.FreePhysicalMemory/1MB,3)
- $UsedRAM = $TotalRAM - $FreeRAM
- $RAMPercentFree = [math]::round(($FreeRAM / $TotalRAM) * 100,3)
- $RAMPercentUsed = [math]::round(($UsedRAM / $TotalRAM) * 100,3)
- $cpuAVG = Get-WmiObject -computername $_ win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
- #Server's Hard Drives (MB) Free/Used
- $disks = Get-WmiObject -Class Win32_LogicalDisk -Computer $_ |
- Where-Object {$_.DriveType -eq 3} |
- ForEach-Object {
- '{0} {1:D} MB Free/{2:D} MB Used' -f $_.DeviceID,
- [int]($_.FreeSpace/1MB), [int]($_.Size/1MB)
- }
- $command.CommandText = "UPDATE ServerList SET FQDN = '$_',
- TotalRAM= '$TotalRAM' ,
- FreeRAM= '$FreeRAM' ,
- UsedRAM= '$UsedRAM' ,
- RAMPercentFree = '$RAMPercentFree' ,
- RAMPercentUsed= '$RAMPercentUsed' ,
- OS = '$($os.Caption)' WHERE ServerName LIKE '$($os.PSComputerName)%';"
- $result = $command.ExecuteNonQuery()
- $command.CommandText = "UPDATE ServerDrives SET
- DriveLetter = '$TotalRAM' ;"
- if ($cpuAVG.Average -ge "20")
- {
- $Outputreport += "<TR bgcolor=#FF0000>"
- }
- else
- {
- $Outputreport += "<TR bgcolor=#E6E6FA>"
- }
- $Outputreport +=
- "<TD>$($os.PSComputerName)</TD>
- <TD align=center>$($_)</TD>
- <TD align=center>$("$($cpuAVG.Average)%")</TD>
- <TD align=center>$("Free: $RAMPercentFree %")`n$("Used: $RAMPercentUsed %")</TD>
- <TD align=center>$("Total: $TotalRAM MB")`n$("Free: $FreeRAM MB")`n$("Used: $UsedRAM MB")</TD>
- <TD align=center>$($disks)</TD>
- <TD align=center>$($os.Caption)</TD></TR>"
- }
- $Outputreport += "</Table></BODY></HTML>"
- $Outputreport | out-file C:UsersKINGDesktopHalOServerReport.html
- Invoke-Expression C:UsersKINGDesktopHalOServerReport.html
- Write-Output "`n End of Hal0";
- #End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement