Guest User

Exports DB Variables in BigIPs

a guest
Dec 23rd, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #################################################################################################
  2. #
  3. #   Generates a table with the db variables
  4. #
  5. #################################################################################################
  6.  
  7. #Setup Credentials
  8. $user = ''
  9. $pass = ''
  10.  
  11. #Array with the IP's of the load balancers you want to compare
  12. #Example: @("10.0.0.1", "192.168.1.1")
  13. $BigIPs = @();
  14.  
  15. $ResultFile = ".\db.html"
  16.  
  17. ################################################################################################
  18. #   End config
  19. ################################################################################################
  20.  
  21. if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ){
  22.     Add-PSSnapIn iControlSnapIn
  23. }
  24.  
  25. #Enable TLS1.2
  26. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  27.  
  28. $bigipdict = @{}
  29. $MasterKeyList = @()
  30. $HTML = ""
  31.  
  32. #Get db key/value from all load balancers
  33. for($i=0;$i -lt $BigIPs.count;$i++){
  34.     $Success = Initialize-F5.iControl -HostName $BigIPs[$i] -Username $user -Password $pass
  35.     $IC = Get-F5.iControl
  36.     $IC.ManagementPartition.set_active_partition('Common')
  37.    
  38.     $BigDB = $ic.ManagementDBVariable.get_list()
  39.     $bigipdict.Add($BigIPs[$i], $BigDB)
  40.    
  41.     $MasterKeyList += (Compare-Object $MasterKeyList $BigDB.name).InputObject
  42. }
  43.  
  44. $HTML = @"
  45.     <table>
  46.         <tr>
  47.             <td>&nbsp;</td>
  48. "@
  49.  
  50. for($i=0;$i -lt $BigIPs.count;$i++){
  51.     $HTML += @"
  52.         <td>$($BigIPs[$i])</td>
  53. "@
  54. }
  55.  
  56. $HTML += @"
  57.         </tr>
  58. "@
  59.  
  60. Foreach($Key in $MasterKeyList){
  61.    
  62.     $HTML += @"
  63.     <tr>
  64.         <td>$Key</td>
  65. "@
  66.     for($i=0;$i -lt $BigIPs.count;$i++){
  67.        
  68.         $value = $bigipdict[$BigIPs[$i]] | Where-Object{ $_.name -eq $Key }
  69.        
  70.         if($value){
  71.             $HTML += @"
  72.         <td>$($value.value)</td>
  73. "@
  74.         } else {
  75.             $HTML += @"
  76.         <td>N/A</td>
  77. "@
  78.         }
  79.     }
  80.    
  81.     $HTML += @"
  82.     </tr>
  83. "@
  84. }
  85.  
  86. $HTML += @"
  87. </table>
  88. "@
  89.  
  90. $HTML | Out-File $ResultFile
Advertisement
Add Comment
Please, Sign In to add comment