Skip to content

Commit 8b0381b

Browse files
authored
Refactor VMFS VMDK Snapshot PowerShell script
Removed legacy @hosts[] array usage
1 parent 30c3881 commit 8b0381b

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

demos-sdk2/VMFS-VMDK Snapshot/VMFS-VMDK Snapshot.ps1

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ $VMESXiHost = Get-VMhost -VM $TargetSQLServerVM
106106

107107

108108

109-
110-
# Get discrete hosts connected to the ESXi cluster
111-
$Hosts = Get-Cluster $ClusterName | Get-VMHost | where-object { ($_.ConnectionState -eq 'Connected') }
112-
113-
114-
115109
# Connect to the target array, authenticate. Remember disclaimer at the top!
116110
$FlashArray = Connect-Pfa2Array -Endpoint $TargetArrayName -Credential ($Credential) -IgnoreCertificateError
117111

@@ -158,7 +152,7 @@ Get-VMHostStorage -RescanAllHba -RescanVmfs -VMHost $VMESXiHost
158152

159153

160154
# Connect to EsxCli
161-
$esxcli = Get-EsxCli -VMHost $Hosts[0]
155+
$esxcli = Get-EsxCli -VMHost $VMESXiHost
162156

163157

164158

@@ -186,7 +180,7 @@ while ($clonedDatastore -eq $null) {
186180
Start-Sleep -Seconds 5
187181
$clonedDatastore = (Get-Datastore | Where-Object { $_.name -match 'snap' -and $_.name -match $SourceDatastoreName })
188182
}
189-
# $clonedDatastore
183+
$clonedDatastore
190184

191185

192186

@@ -268,7 +262,7 @@ Foreach ($SourceVMDKPath in $SourceVMDKPaths) {
268262

269263

270264
# Guest hard disk removed, now remove the stale datastore - this can take a min or two
271-
Remove-Datastore -Datastore $clonedDatastore -VMHost $Hosts[0] -Confirm:$false
265+
Remove-Datastore -Datastore $clonedDatastore -VMHost $VMESXiHost -Confirm:$false
272266

273267

274268

@@ -284,3 +278,4 @@ Remove-Pfa2Volume -Array $FlashArray -Name $NewClonedVolumeName
284278

285279
# Clean up
286280
Remove-PSSession $TargetVMSession
281+

0 commit comments

Comments
 (0)