Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module VMware.VimAutomation.Core
  2. Import-Module VMware.PowerCLI | Out-Null
  3. Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
  4. Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false | Out-Null
  5.  
  6.  
  7.  
  8. Function ESXiConnect
  9. {
  10. #### connect to ESXi host
  11.  
  12.     $ESXiUser = ###ESXiUser
  13.     $ESXiHost = ###ESXiHost
  14.     $ESXiPassword = ###ESXiPassword
  15.     try{
  16.         Connect-VIServer $ESXiHost -User $ESXiUser -Password $ESXiPassword -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
  17.     }
  18.     catch{
  19.         Write-Host "Cant connect to ESXi Server" -ForegroundColor Red
  20.     }
  21. }
  22.  
  23. Function getPDState{
  24.  
  25.     $esxcli = Get-EsxCli -V2
  26.     $sArg = @{
  27.         command = "./storcli  show J"
  28.         workdir = "/opt/lsi/storcli"
  29.     }
  30.     $concount = ($esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json).Controllers.'Response Data'.'Number of Controllers'
  31.     Write-Output "EID/Slt|DID|State|DG|Size|Intf|Med|SED|PI|SeSz|Model|Sp|Type"
  32.     for($controller=0; $controller -le ($concount-1); $controller++)
  33.     {
  34.         $esxcli = Get-EsxCli -V2
  35.         $sArg = @{
  36.             command = "./storcli /c$controller show J"
  37.             workdir = "/opt/lsi/storcli"
  38.         }
  39.         $Output = $esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json
  40.         $PDLIST = $Output.Controllers.'Response Data'.'PD LIST'
  41.         foreach ($PD in $PDLIST)
  42.             {
  43.                 $OutObject = New-Object System.Object
  44.                 $OutObject | Add-Member -type NoteProperty -name EIDSlt -value $PD.'EID:Slt'
  45.                 $OutObject | Add-Member -type NoteProperty -name DID -value $PD.DID
  46.                 $OutObject | Add-Member -type NoteProperty -name State -value $PD.State
  47.                 $OutObject | Add-Member -type NoteProperty -name DG -value $PD.DG
  48.                 $OutObject | Add-Member -type NoteProperty -name Size -value $PD.Size
  49.                 $OutObject | Add-Member -type NoteProperty -name Intf -value $PD.Intf
  50.                 $OutObject | Add-Member -type NoteProperty -name Med -value $PD.Med
  51.                 $OutObject | Add-Member -type NoteProperty -name SED -value $PD.SED
  52.                 $OutObject | Add-Member -type NoteProperty -name PI -value $PD.PI
  53.                 $OutObject | Add-Member -type NoteProperty -name SeSz -value $PD.SeSz
  54.                 $OutObject | Add-Member -type NoteProperty -name Model -value $PD.Model
  55.                 $OutObject | Add-Member -type NoteProperty -name Sp -value $PD.Sp
  56.                 $OutObject | Add-Member -type NoteProperty -name Type -value $PD.Type
  57.                 #output in netXMS table view
  58.                 $OutObject.EIDSlt + '|' + $OutObject.DID + '|' + $OutObject.State + '|' + `
  59.                 $OutObject.DG + '|' + $OutObject.Size + '|' + $OutObject.Intf + '|' + `
  60.                 $OutObject.Med + '|' + $OutObject.SED + '|' + $OutObject.PI + '|' + `
  61.                 $OutObject.SeSz + '|' + $OutObject.Model + '|' + $OutObject.Sp + '|' + $OutObject.Type
  62.             }
  63.     }
  64.  
  65. }
  66.  
  67. Function getVDState{
  68.     $esxcli = Get-EsxCli -V2
  69.     $sArg = @{
  70.         command = "./storcli  show J"
  71.         workdir = "/opt/lsi/storcli"
  72.     }
  73.     $concount = ($esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json).Controllers.'Response Data'.'Number of Controllers'
  74.     Write-Output "DG/VD|Name|TYPE|State|Access|Consist|Cache|Cac|sCC|Size"
  75.     for($controller=0; $controller -le ($concount-1); $controller++)
  76.     {
  77.         $esxcli = Get-EsxCli -V2
  78.         $sArg = @{
  79.             command = "./storcli /c$controller show J"
  80.             workdir = "/opt/lsi/storcli"
  81.         }
  82.         $Output = $esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json
  83.         $VDLIST = $Output.Controllers.'Response Data'.'VD LIST'
  84.         foreach ($VD in $VDLIST)
  85.         {
  86.             $OutObject = New-Object System.Object
  87.             $OutObject | Add-Member -type NoteProperty -name DGVD -value $VD.'DG/VD'
  88.             $OutObject | Add-Member -type NoteProperty -name Type -value $VD.Type
  89.             $OutObject | Add-Member -type NoteProperty -name State -value $VD.State
  90.             $OutObject | Add-Member -type NoteProperty -name Access -value $VD.Access
  91.             $OutObject | Add-Member -type NoteProperty -name Consist -value $VD.Consist
  92.             $OutObject | Add-Member -type NoteProperty -name Cache -value $VD.Cache
  93.             $OutObject | Add-Member -type NoteProperty -name Cac -value $VD.Cac
  94.             $OutObject | Add-Member -type NoteProperty -name sCC -value $VD.sCC
  95.             $OutObject | Add-Member -type NoteProperty -name Size -value $VD.Size
  96.             $OutObject | Add-Member -type NoteProperty -name Name -value $VD.Name
  97.             #output in netXMS table view
  98.             $OutObject.DGVD + '|' + $OutObject.Name + '|' + $OutObject.Type + '|' + `
  99.             $OutObject.State + '|' + $OutObject.Access + '|' + $OutObject.Consist + '|' + `
  100.             $OutObject.Cache + '|' + $OutObject.Cac + '|' + $OutObject.sCC + '|' + $OutObject.Size
  101.         }
  102.     }
  103. }
  104.  
  105. Function GetControllersState{
  106.     $esxcli = Get-EsxCli -V2
  107.     $sArg = @{
  108.         command = "./storcli  show J"
  109.         workdir = "/opt/lsi/storcli"
  110.     }
  111.     $concount = ($esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json).Controllers.'Response Data'.'Number of Controllers'
  112.     Write-Output "Model|Controller|Serial Number|State|Memory Correctable Errors|Memory Uncorrectable Errors"
  113.     for($controllers=0; $controllers -le ($concount-1); $controllers++)
  114.     {  
  115.         $esxcli = Get-EsxCli -V2
  116.         $sArg = @{
  117.             command = "./storcli /c$controllers show all J"
  118.             workdir = "/opt/lsi/storcli"
  119.         }
  120.         $Output = $esxcli.shell.cmd.Invoke($sArg) | ConvertFrom-Json
  121.         $CONTROLLERLIST = $Output.Controllers.'Response Data'
  122.         foreach ($controller in $CONTROLLERLIST)
  123.         {    
  124.             $OutObject = New-Object System.Object
  125.             $OutObject | Add-Member -type NoteProperty -name Model -value $controller.Basics.Model
  126.             $OutObject | Add-Member -type NoteProperty -name Controller -value $controller.Basics.Controller
  127.             $OutObject | Add-Member -type NoteProperty -name SerialNumber -value $controller.Basics.'Serial Number'
  128.             $OutObject | Add-Member -type NoteProperty -name ControllerStatus -value $controller.Status.'Controller Status'
  129.             $OutObject | Add-Member -type NoteProperty -name CorrectableErrors -value $controller.Status.'Memory Correctable Errors'
  130.             $OutObject | Add-Member -type NoteProperty -name UncorrectableErrors -value $controller.Status.'Memory Uncorrectable Errors'
  131.             #output in netXMS table view
  132.             $OutObject.Model + '|' + $OutObject.Controller  + '|' + $OutObject.SerialNumber + '|' + `
  133.             $OutObject.ControllerStatus + '|' + $OutObject.CorrectableErrors + '|' + $OutObject.UncorrectableErrors
  134.         }
  135.     }
  136.  
  137. }
  138.  
  139.  
  140.     ESXiConnect
  141.     GetControllersState
  142.     getVDState
  143.     getPDState
  144.     Disconnect-VIServer -Confirm:$false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement