From 3f475b85d6df7af0157014e8b63732021a536291 Mon Sep 17 00:00:00 2001 From: Malika133 Date: Mon, 11 Sep 2023 15:06:54 +0530 Subject: [PATCH] shifting from management to VMFS script --- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 | 3 +- Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 index 09ad792..923c23a 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psd1 @@ -85,7 +85,8 @@ "Get-StorageAdapters", "Get-VmKernelAdapters", "Set-NVMeTCP", - "New-NVMeTCPAdapter" + "New-NVMeTCPAdapter", + "Set-DatastoreMultipathingPolicy" ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. diff --git a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 index fe63b4e..a816ef8 100644 --- a/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 +++ b/Microsoft.AVS.VMFS/Microsoft.AVS.VMFS.psm1 @@ -1544,3 +1544,40 @@ function New-NVMeTCPAdapter { Write-Host "" } + + +<# + .DESCRIPTION + Set default Multipath Policy to Round Robin. + + .PARAMETER DatastoreName + Datastore name + + .EXAMPLE + Set-DatastoreMultipathingPolicy -DatastoreName "myDatastore" + + .INPUTS + vCenter datastore name. + + .OUTPUTS + None. +#> +function Set-DatastoreMultipathingPolicy { + [CmdletBinding()] + [AVSAttribute(10, UpdatesSDDC = $false, AutomationOnly = $true)] + param( + [Parameter(Mandatory=$true)] + [string]$DatastoreName + ) + try { + $datastore = Get-Datastore -Name $DatastoreName -ErrorAction Stop + $policy = Get-ScsiLun -Datastore $datastore | Get-View | Select-Object -First 1 -ExpandProperty MultipathPolicy + $policy.ChangePolicy("VMW_PSP_RR") + Write-Host "Successfully set Multipath Policy to Round Robin for datastore $DatastoreName." + } + catch { + Write-Error "Failed to set Multipath Policy for datastore $DatastoreName. Error: $($_.Exception.Message)" + } +} + + \ No newline at end of file