GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PowerCLI-Example-Scripts/Scripts/SetLunReservation.ps1 at master · madantnk/PowerCLI-Example-Scripts

Expand file tree

/

SetLunReservation.ps1

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
103 lines (87 loc) · 2.98 KB
/

SetLunReservation.ps1

Copy path

File metadata and controls

103 lines (87 loc) · 2.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<#
.SYNOPSIS
Set a given LUN ID to Perennially Reserved.
.DESCRIPTION
A description of the file.
.PARAMETER vCenter
Set vCenter server to connect to
.PARAMETER Username
Set username to use
.PARAMETER Password
Set password to be used
.PARAMETER VirtualMachine
Name of the virtual machine which has the RDM
.NOTES
===========================================================================
Created on: 20/03/2017 15:05
Created by: Alessio Rocchi <[email protected]>
Organization: VMware
Filename: SetLunReservation.ps1
===========================================================================
#>
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
[ValidateNotNullOrEmpty()]
[String]$vCenter,
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
HelpMessage = 'Set vCenter Username')]
[AllowNull()]
[String]$Username,
[Parameter(Mandatory = $false,
ValueFromPipeline = $true,
HelpMessage = 'Set vCenterPassword')]
[AllowNull()]
[String]$Password,
[Parameter(Mandatory = $true,
ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[String]$VirtualMachine
)
Import-Module -Name VMware.VimAutomation.Core -WarningAction SilentlyContinue -ErrorAction SilentlyContinue | Out-Null
try
{
if ([String]::IsNullOrEmpty($Username) -or [String]::IsNullOrEmpty($Password))
{
$vcCredential = Get-Credential
Connect-VIServer -Server $vCenter -Credential $vcCredential -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
}
else
{
Connect-VIServer -Server $vCenter -User $Username -Password $Password -WarningAction SilentlyContinue -ErrorAction Stop | Out-Null
}
}
catch
{
Write-Error("Error connecting to vCenter: {0}" -f $vCenter)
exit
}
$rDms = Get-HardDisk -DiskType rawPhysical -Vm (Get-VM -Name $VirtualMachine)
$clusterHosts = Get-Cluster -VM $VirtualMachine | Get-VMHost
$menu = @{ }
for ($i = 1; $i -le $rDms.count; $i++)
{
Write-Host("{0}) {1}[{2}]: {3}" -f ($i, $rDms[$i - 1].Name, $rDms[$i - 1].CapacityGB, $rDms[$i - 1].ScsiCanonicalName))
$menu.Add($i, ($rDms[$i - 1].ScsiCanonicalName))
}
[int]$ans = Read-Host 'Which Disk you want to configure?'
$selection = $menu.Item($ans)
write-host("Choosed Disk: {0}" -f $selection)
$current = 0
foreach ($vmHost in $clusterHosts)
{
Write-Progress -Activity "Processing Cluster." -CurrentOperation $vmHost.Name -PercentComplete (($counter / $clusterHosts.count) * 100)
$esxcli = Get-EsxCli -V2 -VMHost $vmHost
$deviceListArgs = $esxcli.storage.core.device.list.CreateArgs()
$deviceListArgs.device = $selection
$esxcli.storage.core.device.list.Invoke($deviceListArgs) | Select-Object Device, IsPerenniallyReserved
$deviceSetArgs = $esxcli.storage.core.device.setconfig.CreateArgs()
$deviceSetArgs.device = $selection
$deviceSetArgs.perenniallyreserved = $true
$esxcli.storage.core.device.setconfig.Invoke($deviceSetArgs)
$counter++
}
Disconnect-VIServer -WarningAction SilentlyContinue -Server $vCenter -Force -Confirm:$false
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.