Skip to content

Instantly share code, notes, and snippets.

@MichaelRyom
Created September 29, 2016 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelRyom/4be0eb386f7afb48e326eb13ce5be256 to your computer and use it in GitHub Desktop.
Save MichaelRyom/4be0eb386f7afb48e326eb13ce5be256 to your computer and use it in GitHub Desktop.
$usernameHost = Read-Host -Prompt 'Host Username'
$secPwHost = Read-Host -Prompt 'Host Password' -AsSecureString
$credHost = New-Object PSCredential -ArgumentList $usernameHost,$secPwHost
$VMHosts = "Host01","Host02","Host03"
foreach($Vmhost in $Vmhosts){
Connect-VIServer $Vmhost -Credential $credHost
$esxcli = Get-EsxCli $VMHost
$rules = $esxcli.corestorage.claimrule.list() | where {[INT]$_.rule -gt "101" -and [INT]$_.rule -ne "65535"}
foreach($rule in $rules){
$Path = $rule.Matches -split("adapter=|channel=|target=|lun=")
$RuleNR = $Rule.rule
$esxcli.corestorage.claimrule.delete($null,$RuleNR)
$esxcli.corestorage.claimrule.load()
$esxcli.corestorage.claiming.unclaim($Path[1].Trim(),[INT]$Path[2],$null,$null,$null,[INT]$Path[4],$null,$null,$null,[INT]$Path[3],"location",$null)
$esxcli.corestorage.claimrule.run()
}
Get-VMHostStorage -VMhost $VMHost -RescanAllHba
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment