SHARE
TWEET

Untitled

a guest Jun 25th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ServerNames = @(
  2.     '192.168.200.144'
  3. )
  4.  
  5. $SleepTimer = 5 <# Default 30: Seconds between loops. #>
  6. $InitialSpeed = 20 <# Default 20: Speed to start at and ramp up or down as it needs to. #>
  7. $Step = 2 <# Default 2: How fast to go up and down as temps change. #>
  8.  
  9. $DracUser = 'root'
  10. $DracPass = 'calvin'
  11. $IpmiPath = "C:\Program Files (x86)\Dell\SysMgt\bmc"
  12. $IpmiTool = Get-ChildItem -Path $ipmiPath "ipmitool.exe"
  13.  
  14. Function Get-SystemType () {
  15.     param( $Foo )
  16.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  17.     $pinfo.FileName = $ipmiTool.FullName
  18.     $pinfo.RedirectStandardError = $true
  19.     $pinfo.RedirectStandardOutput = $true
  20.     $pinfo.UseShellExecute = $false
  21.     $pinfo.Arguments = $Foo.getSystemType
  22.     $pinfo.CreateNoWindow = $true
  23.     $p = New-Object System.Diagnostics.Process
  24.     $p.StartInfo = $pinfo
  25.     $p.Start() | Out-Null
  26.     $p.WaitForExit()
  27.     $stdout = $p.StandardOutput.ReadToEnd()
  28.     $stdout = $stdout -replace "`n", ""
  29.     $stdout = $stdout -replace " ", ""
  30.     Switch ( $stdout ) {
  31.         "1100000f506f776572456467652052373130" { Return "PowerEdge R710" }
  32.         "1100000f506f776572456467652052363130" { Return "PowerEdge R610" }
  33.         default { Return "Unknown system type" }
  34.     }
  35. }
  36.  
  37. Function Get-PowerState (){
  38.     param( $Foo )
  39.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  40.     $pinfo.FileName = $ipmiTool.FullName
  41.     $pinfo.RedirectStandardError = $true
  42.     $pinfo.RedirectStandardOutput = $true
  43.     $pinfo.UseShellExecute = $false
  44.     $pinfo.Arguments = $Foo.GetPowerState
  45.     $pinfo.CreateNoWindow = $true
  46.     $p = New-Object System.Diagnostics.Process
  47.     $p.StartInfo = $pinfo
  48.     $p.Start() | Out-Null
  49.     $p.WaitForExit()
  50.     $stdout = $p.StandardOutput.ReadToEnd()
  51.     If ( $stdout -like "Chassis Power is on*" ) { Return $true }
  52.     Else { Return $false }
  53. }
  54.  
  55. Function Get-RPM (){
  56.     param( $Foo )
  57.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  58.     $pinfo.FileName = $ipmiTool.FullName
  59.     $pinfo.RedirectStandardError = $true
  60.     $pinfo.RedirectStandardOutput = $true
  61.     $pinfo.UseShellExecute = $false
  62.     $pinfo.Arguments = $Foo.GetRPM
  63.     $pinfo.CreateNoWindow = $true
  64.     $p = New-Object System.Diagnostics.Process
  65.     $p.StartInfo = $pinfo
  66.     $p.Start() | Out-Null
  67.     $p.WaitForExit()
  68.     $stdout = $p.StandardOutput.ReadToEnd()
  69.     Return [int]$stdout.Substring( $stdout.IndexOf( "|" ) +1 )
  70. }
  71.  
  72. Function Get-Temp (){
  73.     param( $Foo )
  74.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  75.     $pinfo.FileName = $ipmiTool.FullName
  76.     $pinfo.RedirectStandardError = $true
  77.     $pinfo.RedirectStandardOutput = $true
  78.     $pinfo.UseShellExecute = $false
  79.     $pinfo.Arguments = $Foo.GetTemp
  80.     $pinfo.CreateNoWindow = $true
  81.     $p = New-Object System.Diagnostics.Process
  82.     $p.StartInfo = $pinfo
  83.     $p.Start() | Out-Null
  84.     $p.WaitForExit()
  85.     $stdout = $p.StandardOutput.ReadToEnd()
  86.     Return [int]$stdout.Substring( $stdout.IndexOf( "|" ) +1 )
  87. }  
  88.  
  89. Function Set-Control (){
  90.     param( $Foo, $Type )
  91.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  92.     $pinfo.FileName = $ipmiTool.FullName
  93.     $pinfo.RedirectStandardError = $true
  94.     $pinfo.RedirectStandardOutput = $true
  95.     $pinfo.UseShellExecute = $false  
  96.     If ( $Type -eq "A" ) { $pinfo.Arguments = $Foo.SetAuto }
  97.     If ( $Type -eq "M" ) { $pinfo.Arguments = $Foo.SetManual }
  98.     $pinfo.CreateNoWindow = $true
  99.     $p = New-Object System.Diagnostics.Process
  100.     $p.StartInfo = $pinfo
  101.     $p.Start() | Out-Null
  102.     $p.WaitForExit()
  103. }
  104.  
  105. Function Set-Speed () {
  106.     param( $Foo )
  107.     $pinfo = New-Object System.Diagnostics.ProcessStartInfo
  108.     $pinfo.FileName = $ipmiTool.FullName
  109.     $pinfo.RedirectStandardError = $true
  110.     $pinfo.RedirectStandardOutput = $true
  111.     $pinfo.UseShellExecute = $false
  112.     $pinfo.Arguments = "$( $Foo.SetSpeed )$( "{0:x2}" -f $Foo.Speed )"
  113.     $pinfo.CreateNoWindow = $true
  114.     $p = New-Object System.Diagnostics.Process
  115.     $p.StartInfo = $pinfo
  116.     $p.Start() | Out-Null
  117.     $p.WaitForExit()
  118. }
  119.  
  120.  
  121. [System.Collections.ArrayList]$Servers = @()
  122.  
  123. <#
  124. This is a terribly inefficient way to do this, but it works and is easy to debug, so too bad.
  125. Also, I could have checked if servers are online and skipped them entirely during the initialization, but I didnt on purpose.
  126. I wanted this to be flexible enough to work with servers that go on and off.
  127. #>
  128.  
  129. "Initializing everything. This will take a few seconds per server."
  130.  
  131. ForEach ( $Server in $ServerNames ){
  132.     $TempServer = New-Object -TypeName psobject
  133.     $TempServer | Add-Member -NotePropertyName ServerName -NotePropertyValue $Server
  134.     $TempServer | Add-Member -NotePropertyName BaseArgs -NotePropertyValue "-I lanplus -H $( $TempServer.ServerName ) -U $dracUser -P $dracPass"
  135.    
  136.     $TempServer | Add-Member -NotePropertyName SetAuto -NotePropertyValue "$( $TempServer.BaseArgs ) raw 0x30 0x30 0x01 0x01"
  137.     $TempServer | Add-Member -NotePropertyName SetManual -NotePropertyValue "$( $TempServer.BaseArgs ) raw 0x30 0x30 0x01 0x00"
  138.     $TempServer | Add-Member -NotePropertyName Speed -NotePropertyValue $InitialSpeed
  139.     $TempServer | Add-Member -NotePropertyName SetSpeed -NotePropertyValue "$( $TempServer.BaseArgs ) raw 0x30 0x30 0x02 0xff 0x"
  140.    
  141.     $TempServer | Add-Member -NotePropertyName GetTemp   -NotePropertyValue "$( $TempServer.BaseArgs ) sensor reading `"Ambient Temp`""
  142.     $TempServer | Add-Member -NotePropertyName CurrentTemp -NotePropertyValue ( Get-Temp $TempServer )
  143.     $TempServer | Add-Member -NotePropertyName LastTemp -NotePropertyValue $TempServer.CurrentTemp
  144.  
  145.     $TempServer | Add-Member -NotePropertyName GetSystemType -NotePropertyValue "$( $TempServer.BaseArgs ) raw 0x06 0x59 0x00 0xd1 0x00 0x00"
  146.     $TempServer | Add-Member -NotePropertyName SystemType -NotePropertyValue ( Get-SystemType $TempServer )
  147.    
  148.     $TempServer | Add-Member -NotePropertyName DracOnline -NotePropertyValue ( Test-Connection $TempServer.ServerName -Count 1 -Quiet )
  149.     $TempServer | Add-Member -NotePropertyName GetPowerState -NotePropertyValue "$( $TempServer.BaseArgs ) chassis power status"
  150.     $TempServer | Add-Member -NotePropertyName PoweredOn -NotePropertyValue ( Get-PowerState $TempServer )
  151.    
  152.     <# Adjust for various model servers as needed. #>
  153.     Switch ( $TempServer.SystemType ) {
  154.         "PowerEdge R610" {
  155.             $TempServer | Add-Member -NotePropertyName GetRPM -NotePropertyValue "$( $TempServer.BaseArgs ) sensor reading `"FAN MOD 3A RPM`""
  156.             $TempServer | Add-Member -NotePropertyName MinRPM -NotePropertyValue 2000
  157.             $TempServer | Add-Member -NotePropertyName MinSpeed -NotePropertyValue 10
  158.             $TempServer | Add-Member -NotePropertyName MaxTemp -NotePropertyValue 40
  159.         }
  160.         "PowerEdge R710" {
  161.             $TempServer | Add-Member -NotePropertyName GetRPM -NotePropertyValue "$( $TempServer.BaseArgs ) sensor reading `"FAN 3 RPM`""
  162.             $TempServer | Add-Member -NotePropertyName MinRPM -NotePropertyValue 1000
  163.             $TempServer | Add-Member -NotePropertyName MinSpeed -NotePropertyValue 10
  164.             $TempServer | Add-Member -NotePropertyName MaxTemp -NotePropertyValue 40
  165.         }
  166.         default {  }
  167.     }
  168.    
  169.     $TempServer | Add-Member -NotePropertyName CurrentRPM -NotePropertyValue ( Get-RPM $TempServer )
  170.     $Servers.Add( $TempServer ) | Out-Null
  171. }
  172.  
  173. $Servers | ForEach-Object { Set-Control $_ "M" }
  174. $Servers | ForEach-Object { Set-Speed $Server.Speed }
  175.  
  176. Start-Sleep -Seconds $SleepTimer
  177.  
  178. Do {
  179.     ForEach ( $Server in $Servers ) {
  180.         $Server.DracOnline = Test-Connection $Server.ServerName -Count 1 -Quiet
  181.         $Server.PoweredOn = Get-PowerState $Server
  182.         If ( $Server.DracOnline -and $Server.PoweredOn ) {
  183.             $Server.CurrentTemp = Get-Temp $Server
  184.             Switch ( $Server ) {
  185.                 { $Server.CurrentTemp -ge $Server.MaxTemp } {
  186.                     Set-Control $Server "A"
  187.                     For ( $i = 1 ; $i -le 5 ; $i ++ ) {
  188.                         [console]::Beep( 3000, 100 )
  189.                         [console]::Beep( 2000, 100 )
  190.                         }
  191.                 }
  192.                
  193.                 { $Server.CurrentTemp -le $Server.LastTemp } {
  194.                     If ( ( $Server.Speed - $Step ) -ge $Server.MinSpeed ) { $Server.Speed = $Server.Speed - $Step }
  195.                 }
  196.                
  197.                 { $Server.CurrentTemp -gt $Server.LastTemp } {
  198.                     $Server.Speed = $Server.Speed + ( $Step * 2 )
  199.                 }
  200.             }
  201.         Set-Speed $Server
  202.         $Server.CurrentRPM = Get-RPM $Server    
  203.         $Server.LastTemp = $Server.CurrentTemp    
  204.         }
  205.     }
  206.     $Servers | Where-Object { $_.PoweredOn } | Select-Object `
  207.         @{ Name = "Server Name" ; Expression = { $_.ServerName } } , `
  208.         @{ Name = "Temperature" ; Expression = { $_.CurrentTemp } } , `
  209.         @{ Name = "Fan RPM"; Expression = { $_.CurrentRPM } }, `
  210.         Speed
  211.     Start-Sleep -Seconds $SleepTimer
  212. } While ( $true )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top