Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##########################################
- ## ##
- ## HTML REPORT GENERATION SCRIPT ##
- ## SCRIPT WRITTEN BY :- AMAR ##
- ## ##
- ##########################################
- #------[ VARIABLE DECLARATION ]-------#
- #=====================================#
- $Server= "192.168.0.2";
- $Username="administrator"
- $Password="p@ssw0rd"
- $Report_Path="D:\Report.html"
- $SecurePassWord = ConvertTo-SecureString -AsPlainText $Password -Force
- $Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username,$SecurePassWord
- #------[ HTML COMPONENTS ]-------#
- #================================#
- $Style = "
- <style>
- BODY{background-color:white;}
- TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
- TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#778899}
- TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
- tr:nth-child(odd) { background-color:#d3d3d3;}
- tr:nth-child(even) { background-color:white;}
- </style>
- "
- $StatusColor = @{Stopped = ' bgcolor="Red">Stopped<';Running = ' bgcolor="Green">Running<';}
- #------[ SERVICE CHECK ]-------#
- #==============================#
- $Services = gwmi -Class Win32_Service -ComputerName $Server -Credential $Cred |?{$_.name -match 'Test'} | Select Name,State | Select -last 4 | ConvertTo-HTML -AS Table -Fragment -PreContent '<h2>Services Report</h2>'| Out-String
- $StatusColor.Keys | foreach { $Services = $Services -replace ">$_<",($StatusColor.$_) }
- #------[ DISK CHECK ]-------#
- #===========================#
- $Disk = Get-WmiObject Win32_logicaldisk -ComputerName $Server -Credential $Cred -Filter 'drivetype = 3' | `
- Select-Object DeviceID,@{Name="Total Size(GB)";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}, `
- @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}, `
- @{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}
- $Disk_Report = $Disk | ConvertTo-HTML -AS Table -Fragment -PreContent '<h2>Disk Check Report</h2>'| Out-String
- #------[ SFTP PROFILE CHECK ]-------#
- #===================================#
- $SFTP_Profile=@("FTP_1.tlp","FTP_2.tlp","FTP_3.tlp")
- $FinalOutput = @()
- foreach($profile in $SFTP_Profile)
- {
- $sftp=$null
- $sftp=invoke-expression "D:\sftpc.exe -profile='D:\SFTP_Profiles\$profile' -cmd=ls"
- if ($sftp -like "Connected.")
- {
- $OP = "$profile :: UP"
- $FinalOutput += $OP
- }
- elseif ($sftp -match "ERROR: Connection failed. Connect()" )
- {
- $OP = "$profile :: Connection_Failure"
- $FinalOutput += $OP
- }
- else
- {
- $OP = "$profile :: Down"
- $FinalOutput += $OP
- }
- }
- $SFTP_Table="<br><h2>SFTP Server Connectivity Check</h2><table><tr><th>SMTP Profile</th><th>Status</th></tr>";
- foreach($Output in $FinalOutput )
- {
- $Output = $Output -split " :: "
- $SFTP_Table = $SFTP_Table + "<tr><td>"+$Output[0]+"</td><td>"+$Output[1]+"</td></tr>"
- }
- $SFTP_Table = $SFTP_Table + "</table>"
- $SFTP_StatusColor = @{Down = ' bgcolor="Red">Down<';UP = ' bgcolor="Green">UP<';iOOra_Connection_Failure = ' bgcolor="Red">Down<';}
- $SFTP_StatusColor.Keys | foreach { $SFTP_Table = $SFTP_Table -replace ">$_<",($SFTP_StatusColor.$_) }
- #------[ MERGING ALL THE OUTPUTS INTO HTML FILE ]-------#
- #=======================================================#
- ConvertTo-HTML -head $Style -PostContent $Services, $Disk_Report, $SFTP_Table -PreContent '<h1><u><center>REPORT GENERATION</u></center></h1>'| Out-File $Report_Path
- #------[ END OF SCRIPT]-------#
- #=============================#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement