Merge branch 'master' of github.com:thibautnoben/PowerCLI-Example-Scripts

This commit is contained in:
Thibaut Noben
2019-04-22 21:03:02 +02:00
24 changed files with 5834 additions and 1453 deletions

View File

@@ -3666,13 +3666,19 @@ function New-HVPool {
# flashSettings
#desktopSpec.desktopSettings.flashSettings.quality
[Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")]
[Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')]
[Parameter(Mandatory = $false,ParameterSetName = 'FULL_CLONE')]
[Parameter(Mandatory = $false,ParameterSetName = 'MANUAL')]
[ValidateSet('NO_CONTROL', 'LOW', 'MEDIUM', 'HIGH')]
[string]$quality = 'NO_CONTROL',
[string]$Quality = 'NO_CONTROL',
#desktopSpec.desktopSettings.flashSettings.throttling
[Parameter(Mandatory = $false,ParameterSetName = "LINKED_CLONE")]
[Parameter(Mandatory = $false,ParameterSetName = 'INSTANT_CLONE')]
[Parameter(Mandatory = $false,ParameterSetName = 'FULL_CLONE')]
[Parameter(Mandatory = $false,ParameterSetName = 'MANUAL')]
[ValidateSet('DISABLED', 'CONSERVATIVE', 'MODERATE', 'AGGRESSIVE')]
[string]$throttling = 'DISABLED',
[string]$Throttling = 'DISABLED',
#mirageConfigurationOverrides
#desktopSpec.desktopSettings.mirageConfigurationOverrides.overrideGlobalSetting
@@ -7172,7 +7178,6 @@ function Get-HVMachine {
$machineList = Find-HVMachine -Param $PSBoundParameters
if (!$machineList) {
Write-Host "Get-HVMachine: No Virtual Machine(s) Found with given search parameters"
break
}
$queryResults = @()
$desktop_helper = New-Object VMware.Hv.MachineService
@@ -9319,6 +9324,16 @@ function Set-HVApplicationIcon {
}
process {
if (!(Test-Path $IconPath)) {
Write-Error "File:[$IconPath] does not exist."
break
}
if ([IO.Path]::GetExtension($IconPath) -ne '.png') {
Write-Error "Unsupported file format:[$IconPath]. Only PNG image files are supported."
break
}
try {
$appInfo = Get-HVQueryResult -EntityType ApplicationInfo -Filter (Get-HVQueryFilter data.name -Eq $ApplicationName) -HvServer $HvServer
} catch {
@@ -9332,11 +9347,6 @@ function Set-HVApplicationIcon {
break
}
if (!(Test-Path $IconPath)) {
Write-Error "File:[$IconPath] does not exists"
break
}
$spec = New-Object VMware.Hv.ApplicationIconSpec
$base = New-Object VMware.Hv.ApplicationIconBase
@@ -10170,7 +10180,7 @@ $deleteSpec.DeleteFromDisk = $DeleteFromDisk
$deleteSpec.ArchivePersistentDisk = $false
#Delete the machines
write-host "Attempting to Delete:"
if($DeleteFromDisk){write-host "Attempting to Delete:"}else{write-host "Attempting to remove from inventory:"}
Write-Output ($deleteMachine.base.Name -join "`n")
$bye = $machineService.Machine_DeleteMachines($services,$deleteMachine.id,$deleteSpec)
@@ -11477,4 +11487,102 @@ function Get-HVlicense {
[System.gc]::collect()
}
Export-ModuleMember Add-HVDesktop,Add-HVRDSServer,Connect-HVEvent,Disconnect-HVEvent,Get-HVPoolSpec,Get-HVInternalName, Get-HVEvent,Get-HVFarm,Get-HVFarmSummary,Get-HVPool,Get-HVPoolSummary,Get-HVMachine,Get-HVMachineSummary,Get-HVQueryResult,Get-HVQueryFilter,New-HVFarm,New-HVPool,Remove-HVFarm,Remove-HVPool,Set-HVFarm,Set-HVPool,Start-HVFarm,Start-HVPool,New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement, Set-HVMachine, New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVApplicationIcon, Remove-HVApplicationIcon, Get-HVGlobalSettings, Set-HVGlobalSettings, Set-HVGlobalEntitlement, Get-HVResourceStructure, Get-HVLocalSession, Get-HVGlobalSession, Reset-HVMachine, Remove-HVMachine, Get-HVHealth, New-HVPodfederation, Remove-HVPodFederation, Get-HVPodFederation, Register-HVPod, Unregister-HVPod, Set-HVPodFederation,Get-HVSite,New-HVSite,Set-HVSite,Remove-HVSite,New-HVHomeSite,Get-HVHomeSite,Set-HVEventDatabase,Get-HVEventDatabase,Clear-HVEventDatabase,Get-HVlicense,Set-HVlicense
function Set-HVInstantCloneMaintenance {
<#
.Synopsis
Enable or disable instant clone maintanence mode
.DESCRIPTION
Toggles a host in instant clone maintanence mode. Specify the VMHost name and enable or disable to toggle.
.PARAMETER VMHost
ESXi Host name to modify the InstantClone.Maintenance attribute
.PARAMETER Enable
Enable Instant Clone maintenance mode.
.PARAMETER Disable
Disable Instant Clone maintenance mode
.EXAMPLE
Set-HvInstantCloneMaintenance -VMHost <hostname> -Enable $true
Set-HvInstantCloneMaintenance -VMHost <hostname> -Disable $true
.NOTES
Author : Jack McMichael
Author email : @jackwmc4 / jackwmc4@gmail.com
Version : 1.0
===Tested Against Environment====
Horizon View Server Version : 7.6
PowerCLI Version : PowerCLI 11
PowerShell Version : 5.1
#>
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = 'High')]
param(
[Parameter(Mandatory=$true, Position=0)]
[string]
$VMHost,
[Parameter(Mandatory = $false)]
[switch]
$Enable,
[Parameter(Mandatory = $false)]
[switch]
$Disable,
[Parameter(Mandatory = $false)]
$HvServer = $null
)
begin {
$services = Get-ViewAPIService -hvServer $hvServer
if ($null -eq $services) {
Write-Error "Could not retrieve ViewApi services from connection object"
break
}
}
process {
if ($Enable) {
if ((Get-Annotation -Entity (Get-VMHost -Name $VMHost) -CustomAttribute "InstantClone.Maintenance").Value -eq ""){
Set-Annotation -Entity (Get-VMHost -Name $VMHost) -CustomAttribute "InstantClone.Maintenance" -Value "1" | Out-Null
Write-Host "Instant Clone Maintenance Mode: Enabling for $VMHost...(This could take some time)"
}
while ((Get-Annotation -Entity (Get-VMHost -Name $VMHost) -CustomAttribute "InstantClone.Maintenance").Value -ne "2") {
Start-Sleep -Seconds 10
}
} elseif ($Disable) {
if (-not (Get-Annotation -Entity (Get-VMHost -Name $VMHost) -CustomAttribute "InstantClone.Maintenance").Value -eq "") {
Set-Annotation -Entity (Get-VMHost -Name $VMHost) -CustomAttribute "InstantClone.Maintenance" -Value "" | Out-Null
Write-Host "Instant Clone Maintenance Mode: Disabling for $VMHost"
}
Set-VMhost $VMHost -State Connected | Out-Null
}
[System.gc]::collect()
}
}
# Object related
Export-ModuleMember -Function Get-HVMachine, Get-HVMachineSummary, Get-HVQueryResult, Get-HVQueryFilter, Get-HVInternalName
# RDS Farm related
Export-ModuleMember -Function Get-HVFarmSummary, Start-HVFarm, Start-HVPool, New-HVFarm, Remove-HVFarm, Get-HVFarm, Set-HVFarm, Add-HVRDSServer
# Desktop Pool related
Export-ModuleMember -Function Get-HVPoolSummary, New-HVPool, Remove-HVPool, Get-HVPool, Set-HVPool, Get-HVPoolSpec, Add-HVDesktop
# Entitlement related
Export-ModuleMember -Function New-HVEntitlement,Get-HVEntitlement,Remove-HVEntitlement
Export-ModuleMember -Function Set-HVMachine, Reset-HVMachine, Remove-HVMachine
# Cloud Pod Architecture related
Export-ModuleMember -Function New-HVGlobalEntitlement, Remove-HVGlobalEntitlement, Get-HVGlobalEntitlement, Set-HVGlobalEntitlement, New-HVPodFederation, Remove-HVPodFederation, Get-HVPodFederation, Set-HVPodFederation
Export-ModuleMember -Function Get-HVSite, New-HVSite, New-HVHomeSite, Remove-HVSite, Get-HVHomeSite, Set-HVSite, Register-HVPod, Unregister-HVPod
# Published App related
Export-ModuleMember -Function Get-HVGlobalSettings, Set-HVApplicationIcon, Remove-HVApplicationIcon, Set-HVGlobalSettings
Export-ModuleMember -Function Get-HVResourceStructure, Get-HVLocalSession, Get-HVGlobalSession
# Event Database related
Export-ModuleMember -Function Get-HVEventDatabase, Set-HVEventDatabase, Clear-HVEventDatabase, Get-HVEvent, Connect-HVEvent, Disconnect-HVEvent
# Misc/other related
Export-ModuleMember -Function Get-HVlicense, Set-HVlicense, Get-HVHealth, Set-HVInstantCloneMaintenance