forked from vmware-archive/PowerCLI-Example-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomaticVMFSUnmap.ps1
More file actions
executable file
·75 lines (65 loc) · 2.5 KB
/
Copy pathAutomaticVMFSUnmap.ps1
File metadata and controls
executable file
·75 lines (65 loc) · 2.5 KB
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
<#
Copyright 2021 VMware, Inc.
SPDX-License-Identifier: BSD-2-Clause
#>
<#
.SYNOPSIS Retrieve the current VMFS Unmap priority for VMFS 6 datastore
.NOTES Author: William Lam
.NOTES Site: www.virtuallyghetto.com
.NOTES Reference: http://www.virtuallyghetto.com/2016/10/configure-new-automatic-space-reclamation-vmfs-unmap-using-vsphere-6-5-apis.html
.PARAMETER Datastore
VMFS 6 Datastore to enable or disable VMFS Unamp
.EXAMPLE
Get-Datastore "mini-local-datastore-hdd" | Get-VMFSUnmap
#>
Function Get-VMFSUnmap {
param(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreImpl]$Datastore
)
$datastoreInfo = $Datastore.ExtensionData.Info
if($datastoreInfo -is [VMware.Vim.VmfsDatastoreInfo] -and $datastoreInfo.Vmfs.MajorVersion -eq 6) {
$datastoreInfo.Vmfs | select Name, UnmapPriority, UnmapGranularity
} else {
Write-Host "Not a VMFS Datastore and/or VMFS version is not 6.0"
}
}
<#
.SYNOPSIS Configure the VMFS Unmap priority for VMFS 6 datastore
.NOTES Author: William Lam
.NOTES Site: www.virtuallyghetto.com
.NOTES Reference: http://www.virtuallyghetto.com/2016/10/configure-new-automatic-space-reclamation-vmfs-unmap-using-vsphere-6-5-apis.html
.PARAMETER Datastore
VMFS 6 Datastore to enable or disable VMFS Unamp
.EXAMPLE
Get-Datastore "mini-local-datastore-hdd" | Set-VMFSUnmap -Enabled $true
.EXAMPLE
Get-Datastore "mini-local-datastore-hdd" | Set-VMFSUnmap -Enabled $false
#>
Function Set-VMFSUnmap {
param(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreImpl]$Datastore,
[String]$Enabled
)
$vmhostView = ($Datastore | Get-VMHost).ExtensionData
$storageSystem = Get-View $vmhostView.ConfigManager.StorageSystem
if($Enabled -eq $true) {
$enableUNMAP = "low"
$reconfigMessage = "Enabling Automatic VMFS Unmap for $Datastore"
} else {
$enableUNMAP = "none"
$reconfigMessage = "Disabling Automatic VMFS Unmap for $Datastore"
}
$uuid = $datastore.ExtensionData.Info.Vmfs.Uuid
Write-Host "$reconfigMessage ..."
$storageSystem.UpdateVmfsUnmapPriority($uuid,$enableUNMAP)
}