Advertisement
Guest User

Untitled

a guest
Oct 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. ##########################################
  2. ## ##
  3. ## HTML REPORT GENERATION SCRIPT ##
  4. ## SCRIPT WRITTEN BY :- AMAR ##
  5. ## ##
  6. ##########################################
  7.  
  8. #------[ VARIABLE DECLARATION ]-------#
  9. #=====================================#
  10.  
  11. $Server= "192.168.0.2";
  12. $Username="administrator"
  13. $Password="p@ssw0rd"
  14. $Report_Path="D:\Report.html"
  15.  
  16. $SecurePassWord = ConvertTo-SecureString -AsPlainText $Password -Force
  17. $Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username,$SecurePassWord
  18.  
  19. #------[ HTML COMPONENTS ]-------#
  20. #================================#
  21.  
  22. $Style = "
  23. <style>
  24. BODY{background-color:white;}
  25. TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
  26. TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color:#778899}
  27. TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
  28. tr:nth-child(odd) { background-color:#d3d3d3;}
  29. tr:nth-child(even) { background-color:white;}
  30. </style>
  31. "
  32.  
  33. $StatusColor = @{Stopped = ' bgcolor="Red">Stopped<';Running = ' bgcolor="Green">Running<';}
  34.  
  35. #------[ SERVICE CHECK ]-------#
  36. #==============================#
  37.  
  38. $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
  39. $StatusColor.Keys | foreach { $Services = $Services -replace ">$_<",($StatusColor.$_) }
  40.  
  41. #------[ DISK CHECK ]-------#
  42. #===========================#
  43.  
  44. $Disk = Get-WmiObject Win32_logicaldisk -ComputerName $Server -Credential $Cred -Filter 'drivetype = 3' | `
  45. Select-Object DeviceID,@{Name="Total Size(GB)";Expression={[decimal]("{0:N0}" -f($_.size/1gb))}}, `
  46. @{Name="Free Space(GB)";Expression={[decimal]("{0:N0}" -f($_.freespace/1gb))}}, `
  47. @{Name="Free (%)";Expression={"{0,6:P0}" -f(($_.freespace/1gb) / ($_.size/1gb))}}
  48.  
  49. $Disk_Report = $Disk | ConvertTo-HTML -AS Table -Fragment -PreContent '<h2>Disk Check Report</h2>'| Out-String
  50.  
  51. #------[ SFTP PROFILE CHECK ]-------#
  52. #===================================#
  53.  
  54. $SFTP_Profile=@("FTP_1.tlp","FTP_2.tlp","FTP_3.tlp")
  55. $FinalOutput = @()
  56.  
  57. foreach($profile in $SFTP_Profile)
  58. {
  59. $sftp=$null
  60. $sftp=invoke-expression "D:\sftpc.exe -profile='D:\SFTP_Profiles\$profile' -cmd=ls"
  61.  
  62. if ($sftp -like "Connected.")
  63. {
  64. $OP = "$profile :: UP"
  65. $FinalOutput += $OP
  66. }
  67. elseif ($sftp -match "ERROR: Connection failed. Connect()" )
  68. {
  69. $OP = "$profile :: Connection_Failure"
  70. $FinalOutput += $OP
  71. }
  72. else
  73. {
  74. $OP = "$profile :: Down"
  75. $FinalOutput += $OP
  76. }
  77. }
  78.  
  79. $SFTP_Table="<br><h2>SFTP Server Connectivity Check</h2><table><tr><th>SMTP Profile</th><th>Status</th></tr>";
  80. foreach($Output in $FinalOutput )
  81. {
  82. $Output = $Output -split " :: "
  83. $SFTP_Table = $SFTP_Table + "<tr><td>"+$Output[0]+"</td><td>"+$Output[1]+"</td></tr>"
  84. }
  85.  
  86. $SFTP_Table = $SFTP_Table + "</table>"
  87.  
  88. $SFTP_StatusColor = @{Down = ' bgcolor="Red">Down<';UP = ' bgcolor="Green">UP<';iOOra_Connection_Failure = ' bgcolor="Red">Down<';}
  89. $SFTP_StatusColor.Keys | foreach { $SFTP_Table = $SFTP_Table -replace ">$_<",($SFTP_StatusColor.$_) }
  90.  
  91.  
  92. #------[ MERGING ALL THE OUTPUTS INTO HTML FILE ]-------#
  93. #=======================================================#
  94.  
  95. ConvertTo-HTML -head $Style -PostContent $Services, $Disk_Report, $SFTP_Table -PreContent '<h1><u><center>REPORT GENERATION</u></center></h1>'| Out-File $Report_Path
  96.  
  97.  
  98.  
  99. #------[ END OF SCRIPT]-------#
  100. #=============================#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement