|
| 1 | +<#========================================================================== |
| 2 | +Script Name: RemovePre65PureUserRules |
| 3 | +Created on: 12/20/2021 |
| 4 | +Updated on: 2/08/2021 |
| 5 | +Created by: Jase McCarty |
| 6 | +Github: http://www.github.com/jasemccarty |
| 7 | +Twitter: @jasemccarty |
| 8 | +Website: http://www.jasemccarty.com |
| 9 | +=========================================================================== |
| 10 | +#> |
| 11 | +# Get the PowerCLI Version |
| 12 | +$PowerCLIVersion = Get-Module -Name VMware.PowerCLI -ListAvailable | Select-Object -Property Version |
| 13 | + |
| 14 | +# If the PowerCLI Version is not v12 or higher, recommend that the user install PowerCLI 12 or higher |
| 15 | +If ($PowerCLIVersion.Version.Major -ge "12") { |
| 16 | + Write-Host "PowerCLI version 12 or higher present, " -NoNewLine |
| 17 | + Write-Host "proceeding" -ForegroundColor Green |
| 18 | +} else { |
| 19 | + Write-Host "PowerCLI version could not be determined or is less than version 12" -Foregroundcolor Red |
| 20 | + Write-Host "Please install PowerCLI 12 or higher and rerun this script" -Foregroundcolor Yellow |
| 21 | + Write-Host " " |
| 22 | + exit |
| 23 | +} |
| 24 | + |
| 25 | +############################################################################################################ |
| 26 | +# Function to remove User Rules associated with Pre-vSphere 6.0EP5/6.5U1 installations # |
| 27 | +############################################################################################################ |
| 28 | +Function Remove-PfaVmHostUserRule |
| 29 | +{ |
| 30 | + <# |
| 31 | + .SYNOPSIS |
| 32 | + Remove any User Rules configured for Pure Storage FlashArray |
| 33 | + .DESCRIPTION |
| 34 | + Enumerate any hosts passed and remove any User Rules configured for Pure Storage FlashArray |
| 35 | + .INPUTS |
| 36 | + (Required) A vSphere Host or Hosts Object returned from the Get-VMhost PowerCLI cmdlet |
| 37 | + .OUTPUTS |
| 38 | + Host, Number of User Rules Found, & if they are removed or not. |
| 39 | + .EXAMPLE |
| 40 | + PS C:\ Remove-VmHostUserRule -EsxiHost (Get-VMhost -Name "esxihost.fqdn") |
| 41 | + |
| 42 | + Returns the Host info & recommendations for ESXi Host named 'esxihost.fqdn' |
| 43 | + #> |
| 44 | + [CmdletBinding()] |
| 45 | + Param |
| 46 | + ( |
| 47 | + [Parameter(ValueFromPipeline,Mandatory)] |
| 48 | + [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$EsxiHost |
| 49 | + ) |
| 50 | + |
| 51 | + BEGIN |
| 52 | + {} |
| 53 | + PROCESS |
| 54 | + { |
| 55 | + |
| 56 | + # Loop through the EsxiHosts passed |
| 57 | + $EsxiHost | Foreach-Object { |
| 58 | + |
| 59 | + # Create our EsxCli context for the current host |
| 60 | + $EsxCli = Get-EsxCli -VMHost $_ -V2 |
| 61 | + |
| 62 | + Write-Host "Current VMhost is " -NoNewLine |
| 63 | + Write-Host "$($_): " -ForegroundColor Green -NoNewline |
| 64 | + |
| 65 | + # Retrieve any User storage Rules for Pure Storage |
| 66 | + Write-Host "Retrieving User Rules" -NoNewline |
| 67 | + $SatpUserRules = $esxcli.storage.nmp.satp.rule.list.Invoke()| Where-Object {($_.RuleGroup -eq "user") -and ({$_.Model -Like "FlashArray"})} |
| 68 | + |
| 69 | + # IF we have 1 or more rules, |
| 70 | + if ($SatpUserRules.Count -ge "1") { |
| 71 | + Write-Host "Found " -NoNewLine |
| 72 | + Write-Host "$($SatpUserRules.Count) " -ForegroundColor Yellow -NoNewline |
| 73 | + Write-Host "user rules. " -NoNewLine |
| 74 | + |
| 75 | + # Loop through each User rule and remove it. |
| 76 | + $SatpUserRules | Foreach-Object { |
| 77 | + |
| 78 | + # Create an object to assign our arguments to |
| 79 | + $SatpArgs = $esxcli.storage.nmp.satp.rule.remove.CreateArgs() |
| 80 | + |
| 81 | + # Populate the argument object with the current User rule's properties |
| 82 | + $SatpArgs.model = $_.Model |
| 83 | + $SatpArgs.pspoption = $_.PSPOptions |
| 84 | + $SatpArgs.vendor = $_.Vendor |
| 85 | + $SatpArgs.description = $_.Description |
| 86 | + $SatpArgs.psp = $_.DefaultPSP |
| 87 | + $SatpArgs.satp = $_.Name |
| 88 | + |
| 89 | + # Remove the User rule |
| 90 | + Write-Host "Removing the current User rule for Pure Storage" |
| 91 | + $esxcli.storage.nmp.satp.rule.remove.invoke($SatpArgs) |
| 92 | + } |
| 93 | + } else { |
| 94 | + Write-Host "No User rules were found on " -NoNewLine |
| 95 | + Write-Host "$($_)" -ForegroundColor Green |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + END |
| 100 | + {} |
| 101 | +} #END Function Remove-PfaVmHostUserRule |
| 102 | + |
| 103 | +$VMhosts = Get-VMhost | Sort-Object Name |
| 104 | + |
| 105 | +Remove-PfaVmHostUserRule -EsxiHost $VMhosts |
0 commit comments