Skip to content

Commit 8ba6395

Browse files
authored
Create Add-PureUserRules.ps1
1 parent aadee90 commit 8ba6395

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<#==========================================================================
2+
Script Name: Add-PureUserRules.ps1
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 Add-PfaVmHostUserRule
29+
{
30+
<#
31+
.SYNOPSIS
32+
Add User Rules configured for Pure Storage FlashArray
33+
.DESCRIPTION
34+
Enumerate any hosts passed and add 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 added or not.
39+
.EXAMPLE
40+
PS C:\ Add-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 -eq "0") {
71+
72+
# Create an object to assign our arguments to
73+
$SatpArgs = $esxcli.storage.nmp.satp.rule.add.CreateArgs()
74+
75+
# Populate the argument object with the current User rule's properties
76+
$SatpArgs.model = "FlashArray"
77+
$SatpArgs.pspoption = "iops=1"
78+
$SatpArgs.vendor = "PURE"
79+
$SatpArgs.description = "Pure Storage FlashArray SATP"
80+
$SatpArgs.psp = "VMW_PSP_RR"
81+
$SatpArgs.satp = "VMW_SATP_ALUA"
82+
83+
# Add the User rule
84+
Write-Host "Adding the current User rule for Pure Storage"
85+
$esxcli.storage.nmp.satp.rule.add.invoke($SatpArgs)
86+
87+
} else {
88+
Write-Host "User rule already found on " -NoNewLine
89+
Write-Host "$($_)" -ForegroundColor Green
90+
}
91+
}
92+
}
93+
END
94+
{}
95+
} #END Function Add-PfaVmHostUserRule
96+
97+
$VMhosts = Get-VMhost | Sort-Object Name
98+
99+
Add-PfaVmHostUserRule -EsxiHost $VMhosts

0 commit comments

Comments
 (0)