Guest User

NetworkMonitor

a guest
Jul 3rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Add-Type -AssemblyName office
  2. $Application = New-Object -ComObject PowerPoint.Application  #start a new ComObject to launch powerpoint
  3. $Application.Visible = [Microsoft.Office.Core.MsoTriState]::msoTrue   #make the powerpoint app visible
  4. $slideType = "microsoft.office.interop.powerpoint.ppSlideLayout" -as [type]
  5. $datadir = "c:\Script\Data"   #set the Directory where all the data resides
  6. $templatePresentation = "C:\Script\Network-Monitor5.pptx"  #assign our powerpoint presentation
  7. $presentation = $application.Presentations.open($templatePresentation)  #this opens it
  8. $mydocument = $presentation.Slides.item(1)   #this makes slide 1 the active one
  9. $mydocument.Shapes.Item("status").width = 120
  10. [int]$hour = Get-Date -format HH
  11. ############################################ Instantiate (initialize) the hash tables ##################################################################################
  12.  
  13. $PrinterIP = ((Get-Content $datadir\Printers-IP-new.csv) -replace ",","=") -join "`n"|ConvertFrom-StringData
  14. $SwitchIP = ((Get-Content $datadir\Switches-IP.csv) -replace ",","=") -join "`n"|ConvertFrom-StringData
  15. $NetworkIP = ((Get-Content $datadir\Network-IP.csv) -replace ",","=") -join "`n"|ConvertFrom-StringData
  16. $ServerIP = ((Get-Content $datadir\Server-IP.csv) -replace ",","=") -join "`n"|ConvertFrom-StringData
  17.  
  18. ############################################ End Instantiate (initialize) the hash tables ##############################################################################
  19.  
  20.  
  21. ############################################ CheckStatus Function Start ##################################################################
  22. #We write the function first because if you call the function before powershell sees it,  it will not recognize the function and give you an error
  23.  
  24. Function CheckStatus ($deviceip) {
  25.  $tc = New-Object System.Net.Networkinformation.ping   #connect to Microsoft network to ping
  26.  $mydocument.Shapes.Item("status").Fill.Transparency = 0.15   #set the "status" transparencyy
  27.  ForEach ($ip in $deviceip.GetEnumerator()) {   #loop through each network device's IP
  28.  $Status = $tc.Send($ip.Value).Status  #send a ping and get the status.  Store it in $status variable.
  29.  
  30. Switch ($status) {
  31.  
  32. "Success" {
  33.  
  34.  
  35.  
  36.  
  37. $mydocument.Shapes.Item($ip.Name).Fill.forecolor.RGB = "255,0,100"   #change it to green color.
  38. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 1.0  #Make it invisible briefly for effect
  39.  
  40. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 0.15 #Set transparency back
  41.  
  42.  
  43. }
  44.  
  45. "TimedOut" {
  46. $mydocument.Shapes.Item($ip.Name).Fill.forecolor.RGB =  "255,255,255"  #change it to red to show we can't communicate
  47. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 1
  48.  
  49. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 0.15
  50.  
  51.  
  52.  
  53. }
  54. "DestinationHostUnreachable" {
  55.  
  56. $mydocument.Shapes.Item($ip.Name).Fill.forecolor.RGB =  "118,240,255"   #change it to yellow
  57. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 1
  58. $mydocument.Shapes.Item($ip.Name).Fill.Transparency = 0.15
  59.  
  60. }
  61.  
  62.  
  63.  
  64.         }
  65.     }
  66. }
  67. ##################################################### Check Status Function End ########################################################################
  68.  
  69.  
  70. While ($env:UserName -ne "Satan"){       # keep running until we exit the script.  It's looking for Ctuhlu as a username it will never happen.
  71.  
  72. if($hour -lt 8 -or $hour -gt 16){}#do nothing
  73. Else {
  74. CheckStatus $PrinterIP   #calls the check status function and passes info from our hashes declared above.
  75. CheckStatus $SwitchIP
  76. CheckStatus $NetworkIP
  77. CheckStatus $ServerIP
  78.  
  79. [System.Windows.Forms.SendKeys]::SendWait("^")  #don't allow the screen saver from GPO to kick in
  80. ######################################### Start Timer Countdown ###########################################################################################################
  81. for ($a=120; $a -ge 0; $a--) {  #this is a timer. Set the $a= to however long you want the timer.  You will have to manually adjust the status bar length in the ppx
  82.  
  83.   $mydocument.Shapes.Item("status").width = $a  #this is the update status bar.  It decreases the size of the shape.
  84.   $mydocument.Shapes.Item("timer").Textframe.TextRange.text = "$a SECONDS"
  85.   Start-Sleep 1
  86. }
  87.  
  88. ####################################### End Timer Countdown ##############################################################################################################
  89.  
  90.  
  91. $mydocument.Shapes.Item("status").width = 120  #set the green status bar back to default length
  92. $mydocument.Shapes.Item("timer").TextFrame.TextRange.text = "120 SECONDS"  #reset the timer display
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment