From 356b3c4d689e3bcf650ee759ed9d2826fd7cbd71 Mon Sep 17 00:00:00 2001 From: desrosim232 <131466573+desrosim232@users.noreply.github.com> Date: Tue, 27 Jun 2023 08:07:14 -0400 Subject: [PATCH 1/7] Update VMware.HV.Helper.psm1 Adding new parameters for Start-HVFarm function to configure the ComputeProfile of the VMs underlying a farm: NumCPU Ram CoresPerSocket Signed-off-by: Mathieu Desrosiers desrosim@gmail.com --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 7a5df6a..10346fd 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -1,7 +1,7 @@ #Script Module : VMware.Hv.Helper #Version : 1.3.1 -#Copyright © 2016 VMware, Inc. All Rights Reserved. +#Copyright © 2016 VMware, Inc. All Rights Reserved. #Permission is hereby granted, free of charge, to any person obtaining a copy of #this software and associated documentation files (the "Software"), to deal in @@ -6569,6 +6569,16 @@ function Start-HVFarm { How frequently to repeat maintenance, expressed as a multiple of the maintenance period. e.g. Every 2 weeks. This property has a default value of 1. This property has values 1-100. +.PARAMETER NumCPU + Number of CPU of the Vm Instances + +.PARAMETER Ram + Ram of the Vm Instances + Units in MB for Ram parameter + +.PARAMETER CoresPerSocket + CoresPerSocket of the Vm Instances + .PARAMETER HvServer Reference to Horizon View Server to query the data from. If the value is not passed or null then first element from global:DefaultHVServers would be considered in-place of hvServer. @@ -6673,6 +6683,21 @@ function Start-HVFarm { [ValidateRange(1, 100)] [int]$EveryInt = 1, + [Parameter(Mandatory = $false)] + [ValidateRange(1,[Int]::MaxValue)] + [int] + $NumCPU = 4, + + [Parameter(Mandatory = $false)] + [ValidateRange(1,[Int]::MaxValue)] + [int] + $Ram = 16384, + + [Parameter(Mandatory = $false)] + [ValidateRange(1,[Int]::MaxValue)] + [int] + $CoresPerSocket = 1, + [Parameter(Mandatory = $false)] $HvServer = $null ) @@ -6820,6 +6845,13 @@ function Start-HVFarm { break } } + + #set ComputeProfile in a SCHEDULEMAINTENANCE + $spec.ComputeProfile = New-Object VMware.Hv.FarmComputeProfileSpec + $spec.ComputeProfile.NumCPU = $NumCPU + $spec.ComputeProfile.Ram = $Ram + $spec.ComputeProfile.CoresPerSocket = $CoresPerSocket + # call scheduleMaintenance service on farm if (!$confirmFlag -OR $pscmdlet.ShouldProcess($farmList.$item)) { $farm_service_helper.Farm_ScheduleMaintenance($services, $item, $spec) From 2be8d0570775d17c7979b91e63890f0ed1f47440 Mon Sep 17 00:00:00 2001 From: desrosim232 <131466573+desrosim232@users.noreply.github.com> Date: Tue, 27 Jun 2023 08:08:53 -0400 Subject: [PATCH 2/7] Update VMware.HV.Helper.psm1 Encoding correction Signed-off-by: Mathieu Desrosiers desrosim@gmail.com --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 10346fd..14f4245 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -1,7 +1,7 @@ #Script Module : VMware.Hv.Helper #Version : 1.3.1 -#Copyright © 2016 VMware, Inc. All Rights Reserved. +#Copyright © 2016 VMware, Inc. All Rights Reserved. #Permission is hereby granted, free of charge, to any person obtaining a copy of #this software and associated documentation files (the "Software"), to deal in From d70d246e3416b4523ca2716815792cf8a90e9748 Mon Sep 17 00:00:00 2001 From: Kamen Nikolov Date: Mon, 31 Jul 2023 16:23:56 +0300 Subject: [PATCH 3/7] Added Power Actions sample actions Signed-off-by: Kamen Nikolov --- .../Example - ClusterSnapshotsReport.ps1 | 51 +++++++++++++++++++ .../Example - RemoveOldClusterSnapshots.ps1 | 17 +++++++ 2 files changed, 68 insertions(+) create mode 100644 PowerActions/Example - ClusterSnapshotsReport.ps1 create mode 100644 PowerActions/Example - RemoveOldClusterSnapshots.ps1 diff --git a/PowerActions/Example - ClusterSnapshotsReport.ps1 b/PowerActions/Example - ClusterSnapshotsReport.ps1 new file mode 100644 index 0000000..261a7c0 --- /dev/null +++ b/PowerActions/Example - ClusterSnapshotsReport.ps1 @@ -0,0 +1,51 @@ +param ( + [Parameter(Mandatory=$true)] + [VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster[]] $cluster, + [Parameter(Mandatory=$true)] + [string] $smtp, + [Parameter(Mandatory=$true)] + [string] $email) + +$vms = Get-VM -Location $cluster +$snapshots = @() +foreach ($vm in $vms) { + $snapshots += Get-Snapshot -VM $vm +} + +$header = @" + +"@ + +$snapshots | select Name,VM,Created,@{Name="Size";Expression={[math]::Round($_.SizeMB,3)}},IsCurrent | ` + ConvertTo-Html -head $header | Out-File "SnapshotReport.html" + +Send-MailMessage -from "Snapshot Reports " ` + -to $email ` + -subject "Snapshot Report" ` + -body "Cluster snapshot report" ` + -Attachment "SnapshotReport.html" ` + -smtpServer $smtp \ No newline at end of file diff --git a/PowerActions/Example - RemoveOldClusterSnapshots.ps1 b/PowerActions/Example - RemoveOldClusterSnapshots.ps1 new file mode 100644 index 0000000..698a15d --- /dev/null +++ b/PowerActions/Example - RemoveOldClusterSnapshots.ps1 @@ -0,0 +1,17 @@ +param ( + [Parameter(Mandatory=$true)] + [VMware.VimAutomation.ViCore.Types.V1.Inventory.Cluster] $cluster, + [DateTime] $date) + +if ($null -eq $date) { + $date = (Get-Date).AddDays(-7) +} + +$vms = Get-VM -Location $cluster +foreach ($vm in $vms) { + $snaphostsToBeRemoved = Get-Snapshot -VM $vm | where {$_.Created -lt $date} + if ($null -ne $snaphostsToBeRemoved) { + Write-Host "Removing snapshots: " + $snaphostsToBeRemoved + " of VM: " + $vm + Remove-Snapshot $snaphostsToBeRemoved -Confirm:$false + } +} \ No newline at end of file From d43b7ec88b4a10072d114bc1d82bf8408ca284a7 Mon Sep 17 00:00:00 2001 From: GeoRon Date: Wed, 6 Sep 2023 15:39:36 +0200 Subject: [PATCH 4/7] enabled vGPU profile for instant clones Signed-off-by: GeoRon --- .../VMware.Hv.Helper/VMware.HV.Helper.psm1 | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 14f4245..e2c2727 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -3925,18 +3925,26 @@ function New-HVPool { [boolean]$enableHTMLAccess = $false, # DesktopPCoIPDisplaySettings - #desktopSpec.desktopSettings.logoffSettings.pcoipDisplaySettings.renderer3D + #desktopSpec.desktopSettings.DisplayProtocolSettings.pcoipDisplaySettings.renderer3D [Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')] [Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")] [Parameter(Mandatory = $false,ParameterSetName = 'MANUAL')] [ValidateSet('MANAGE_BY_VSPHERE_CLIENT', 'AUTOMATIC', 'SOFTWARE', 'HARDWARE', 'DISABLED')] [string]$renderer3D = 'DISABLED', - #desktopSpec.desktopSettings.logoffSettings.pcoipDisplaySettings.enableGRIDvGPUs + #desktopSpec.desktopSettings.DisplayProtocolSettings.pcoipDisplaySettings.enableGRIDvGPUs [Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")] [Parameter(Mandatory = $false,ParameterSetName = 'MANUAL')] + [Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')] [boolean]$enableGRIDvGPUs = $false, + #desktopSpec.desktopSettings.DisplayProtocolSettings.pcoipDisplaySettings.VGPUGridProfile + [Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")] + # [Parameter(Mandatory = $false,ParameterSetName = 'MANUAL')] + [Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')] + [ValidateSet('grid_m10-0b','grid_m10-1b','grid_m10-2b','grid_m10-0q','grid_m10-1q','grid_m10-2q','grid_m10-4q','grid_m10-8q')] + [string]$VGPUGridProfile = $null, + #desktopSpec.desktopSettings.logoffSettings.pcoipDisplaySettings.vRamSizeMB [Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")] [ValidateRange(64,512)] @@ -4658,6 +4666,7 @@ function New-HVPool { if ($null -ne $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings) { $renderer3D = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.renderer3D $enableGRIDvGPUs = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.enableGRIDvGPUs + $VGPUGridProfile = $jsonObject.DesktopSettings.DisplayProtocolSettings.PcoipDisplaySettings.VGPUGridProfile if ($jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.vRamSizeMB) { $vRamSizeMB = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.vRamSizeMB } @@ -4981,6 +4990,17 @@ function New-HVPool { $desktopPCoIPDisplaySettings.setRenderer3D($renderer3D) #setEnableGRIDvGPUs is not exists, because this property cannot be updated. $desktopPCoIPDisplaySettings.getDataObject().EnableGRIDvGPUs = $enableGRIDvGPUs + $desktopPCoIPDisplaySettings.getDataObject().EnableGRIDvGPUs = $enableGRIDvGPUs + if ($enableGRIDvGPUs -eq $true -and $renderer3D -ne 'MANAGE_BY_VSPHERE_CLIENT' -and $InstantClone -eq $true) { + Write-Error "Enabling GRID support requires that 3D rendering be managed by the vSphere client" + break + } + if ($enableGRIDvGPUs -eq $true -and [string]::IsNullOrEmpty($VGPUGridProfile) -eq $true -and $InstantClone -ne $true) { + Write-Error "Enabling GRID support for Instant clones, this requires a specified VGPUGridProfile" + break + } else { + $desktopPCoIPDisplaySettings.getDataObject().VGPUGridProfile = $VGPUGridProfile + } $desktopPCoIPDisplaySettings.setVRamSizeMB($vRamSizeMB) $desktopPCoIPDisplaySettings.setMaxNumberOfMonitors($maxNumberOfMonitors) $desktopPCoIPDisplaySettings.setMaxResolutionOfAnyOneMonitor($maxResolutionOfAnyOneMonitor) From cd502a516b581c0bf11be3d162870de3ac1bca42 Mon Sep 17 00:00:00 2001 From: GeoRon Date: Wed, 6 Sep 2023 15:41:49 +0200 Subject: [PATCH 5/7] removed duplicate line Signed-off-by: GeoRon --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index e2c2727..3846e6f 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -4990,7 +4990,6 @@ function New-HVPool { $desktopPCoIPDisplaySettings.setRenderer3D($renderer3D) #setEnableGRIDvGPUs is not exists, because this property cannot be updated. $desktopPCoIPDisplaySettings.getDataObject().EnableGRIDvGPUs = $enableGRIDvGPUs - $desktopPCoIPDisplaySettings.getDataObject().EnableGRIDvGPUs = $enableGRIDvGPUs if ($enableGRIDvGPUs -eq $true -and $renderer3D -ne 'MANAGE_BY_VSPHERE_CLIENT' -and $InstantClone -eq $true) { Write-Error "Enabling GRID support requires that 3D rendering be managed by the vSphere client" break From f748f2591ed78137e989cd7a0ea3d5b5a91d46d2 Mon Sep 17 00:00:00 2001 From: GeoRon Date: Wed, 6 Sep 2023 16:07:06 +0200 Subject: [PATCH 6/7] enabled addVTPM for instant clones Signed-off-by: GeoRon --- Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 index 14f4245..1759b34 100644 --- a/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 +++ b/Modules/VMware.Hv.Helper/VMware.HV.Helper.psm1 @@ -4010,6 +4010,12 @@ function New-HVPool { [string] $SnapshotVM, + #desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.addVirtualTPM if INSTANT_CLONE, ??? + # [Parameter(Mandatory = $true,ParameterSetName = "LINKED_CLONE")] + [Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')] + [ValidateNotNullOrEmpty()] + [boolean]$addVirtualTPM = $false, + #desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterProvisioningData.vmFolder if LINKED_CLONE, INSTANT_CLONE, FULL_CLONE [Parameter(Mandatory = $true,ParameterSetName = "LINKED_CLONE")] [Parameter(Mandatory = $true,ParameterSetName = 'INSTANT_CLONE')] @@ -4515,6 +4521,9 @@ function New-HVPool { if ($null -ne $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.Snapshot) { $snapshotVM = $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.Snapshot } + if ($null -ne $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.addVirtualTPM) { + $addVirtualTPM = $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.addVirtualTPM + } $dataCenter = $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.dataCenter $vmFolder = $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.VmFolder $hostOrCluster = $jsonObject.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.HostOrCluster @@ -4907,6 +4916,7 @@ function New-HVPool { $desktopSpecObj.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData = $desktopVirtualCenterProvisioningData $desktopSpecObj.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterStorageSettings = $desktopVirtualCenterStorageSettings $desktopSpecObj.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.VirtualCenterNetworkingSettings = $DesktopVirtualCenterNetworkingSettings + $desktopSpecObj.AutomatedDesktopSpec.VirtualCenterProvisioningSettings.AddVirtualTPM = $AddVirtualTPM $desktopSpecObj.AutomatedDesktopSpec.CustomizationSettings = $desktopCustomizationSettings $desktopSpecObj.AutomatedDesktopSpec.ProvisioningType = $provisioningType $desktopSpecObj.AutomatedDesktopSpec.VirtualCenter = $virtualCenterID @@ -4915,6 +4925,7 @@ function New-HVPool { $DesktopVirtualCenterProvisioningSettings.VirtualCenterProvisioningData = $desktopVirtualCenterProvisioningData $DesktopVirtualCenterProvisioningSettings.VirtualCenterStorageSettings = $desktopVirtualCenterStorageSettings $DesktopVirtualCenterProvisioningSettings.VirtualCenterNetworkingSettings = $DesktopVirtualCenterNetworkingSettings + $DesktopVirtualCenterProvisioningSettings.AddVirtualTPM = $AddVirtualTPM $DesktopAutomatedDesktopSpec = New-Object VMware.Hv.DesktopAutomatedDesktopSpec $DesktopAutomatedDesktopSpec.ProvisioningType = $provisioningType From ce06c5372bd93327076a538f46eac7b9145ccc27 Mon Sep 17 00:00:00 2001 From: Kamen Nikolov Date: Tue, 21 Nov 2023 16:52:47 +0200 Subject: [PATCH 7/7] Added git sync script and fixed an issue in the remove old snapshots script in the PowerActions folder --- .../Example - RemoveOldClusterSnapshots.ps1 | 2 +- PowerActions/Git Sync.ps1 | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 PowerActions/Git Sync.ps1 diff --git a/PowerActions/Example - RemoveOldClusterSnapshots.ps1 b/PowerActions/Example - RemoveOldClusterSnapshots.ps1 index 698a15d..66bf771 100644 --- a/PowerActions/Example - RemoveOldClusterSnapshots.ps1 +++ b/PowerActions/Example - RemoveOldClusterSnapshots.ps1 @@ -11,7 +11,7 @@ $vms = Get-VM -Location $cluster foreach ($vm in $vms) { $snaphostsToBeRemoved = Get-Snapshot -VM $vm | where {$_.Created -lt $date} if ($null -ne $snaphostsToBeRemoved) { - Write-Host "Removing snapshots: " + $snaphostsToBeRemoved + " of VM: " + $vm + Write-Host "Removing snapshots: '$snaphostsToBeRemoved' of VM: '$vm'" Remove-Snapshot $snaphostsToBeRemoved -Confirm:$false } } \ No newline at end of file diff --git a/PowerActions/Git Sync.ps1 b/PowerActions/Git Sync.ps1 new file mode 100644 index 0000000..6015448 --- /dev/null +++ b/PowerActions/Git Sync.ps1 @@ -0,0 +1,44 @@ +#Intall git +tdnf install -y git + +#Clone the repo +git clone -n --depth=1 --filter=tree:0 https://github.com/vmware/PowerCLI-Example-Scripts.git +cd PowerCLI-Example-Scripts +git sparse-checkout set --no-cone PowerActions +git checkout +cd PowerActions + +#Select the content library in which you want to store the scirpts from the repo +$contentLibraryName = 'Power Actions' +$contentLibrary = Get-ContentLibrary $contentLibraryName + +#Get all the files that we have cloned from the repo +$files = Get-ChildItem -Path . -File +foreach ($file in $files) { + $name = $file.BaseName + + #Check if the item for this file already exists in the content library + $item = Get-ContentLibraryItem -Name $name -ContentLibrary $contentLibrary -ErrorAction SilentlyContinue + if ($item) { + #If the item exists, check if it is up to date + #Create a folder to store the current content library item + if (-not (Test-Path -Path ./cl_versions -PathType Container)) + { + New-Item -Path ./cl_versions -ItemType Directory + } + #Download the item from the content library + $clFile = Export-ContentLibraryItem -ContentLibraryItem $item -Destination ((Get-Location).Path + "/cl_version") -Force + #Compare if it's the same as the file we have downloaded from the repo + $compResult = Compare-Object -ReferenceObject (Get-Content $file.FullName) -DifferenceObject (Get-Content ($clFile.FullName+"/"+$file.Name)) + if ($compResult) { + #If the item is not up to date, update it + Write-Host "Updating $name" + Set-ContentLibraryItem -ContentLibraryItem $item -Files $file.FullName + } else { + Write-Host "$name is up to date" + } + } else { + #If the item does not exist, create it + New-ContentLibraryItem -Name $name -Files $file.FullName -ContentLibrary $contentLibrary + } +} \ No newline at end of file