diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 index e635a9e..88fc485 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 @@ -72,6 +72,7 @@ "Set-VmfsStaticIscsi", "New-VmfsDatastore", "Dismount-VmfsDatastore", + "Resize-iSCSIDatastore", "Resize-VmfsVolume", "Restore-VmfsVolume", "Sync-VMHostStorage", diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index b5dc191..7e0c718 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -527,6 +527,68 @@ function Resize-VmfsVolume { $DatastoreSystem.ExpandVmfsDatastore($DatastoreToResize.ExtensionData.MoRef, $ExpandOptions[0].spec) } +<# + .DESCRIPTION + Expand existing iSCSI Datastore to new size. + + .PARAMETER ClusterName + Cluster name + + .PARAMETER DatastoreName + Datastore name + + .EXAMPLE + Resize-iSCSIDatastore -ClusterName "myCluster" -DatastoreName "myDatastore" + + .INPUTS + vCenter cluster name and datastore name. + + .OUTPUTS + None. +#> +function Resize-iSCSIDatastore { + [CmdletBinding()] + [AVSAttribute(10, UpdatesSDDC = $false)] + Param ( + [Parameter( + Mandatory=$true, + HelpMessage = 'Cluster name in vCenter')] + [ValidateNotNull()] + [String] + $ClusterName, + + [Parameter( + Mandatory=$true, + HelpMessage = 'Name of iSCSI datastore to be expanded in vCenter')] + [ValidateNotNull()] + [String] + $DatastoreName + ) + + $Cluster = Get-Cluster -Name $ClusterName -ErrorAction Ignore + if (-not $Cluster) { + throw "Cluster $ClusterName does not exist." + } + + $Datastore = Get-Datastore -Name $DatastoreName -ErrorAction Ignore + if (-not $Datastore) { + throw "Datastore $DatastoreName does not exist." + } + + if ($Datastore.Type -ne "VMFS") { + throw "Datastore $DatastoreName is of type $($Datastore.Type). This cmdlet can only process iSCSI datastores." + } + + $NaaID = [string]$Datastore.ExtensionData.Info.Vmfs.Extent.DiskName + if (-not $NaaID) { + throw "Failed to get NAA ID for datastore $DatastoreName." + + } + + Write-Host "Resizing iSCSI datastore $DatastoreName..." + Resize-VmfsVolume -ClusterName $ClusterName -DeviceNaaId $NaaID +} + <# .DESCRIPTION Re-signature existing VMFS volume to recover to previous version.