-
Notifications
You must be signed in to change notification settings - Fork 6
/
Assign-TagQOS.ps1
35 lines (24 loc) · 972 Bytes
/
Assign-TagQOS.ps1
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
function Assign-TagQOS {
param(
[Parameter(Mandatory = $True)]
[ValidateNotNullOrEmpty()]
[string]$vCenterServer
)
$ErrorActionPreference = 'stop'
Add-PSSnapin VMware.VimAutomation.Core
$Session = Connect-VIServer -Server $vCenterServer 3>&1 | Out-Null
Get-Tag -Name "QOS_*" | ForEach-Object {
try {
$tag = $_
IF ($tag.name -eq "QOS_NOLIMIT") {
$Limit = $null ; $Check = -1
} ELSE {
$Limit = (($tag.name).Trim("QOS_")) ; $Check = $Limit
}
Get-VM -Tag $tag | Get-VMResourceConfiguration | Where-Object {$_.CpuLimitMhz -ne $Check} |
Set-VMResourceConfiguration -CpuLimitMhz $Limit | Select-Object VM,@{l='Tag';e={$tag.name}},CpuLimitMhz
}
catch {Write-Error $_.Exception -ErrorAction Continue}
Clear-Variable Limit,tag
}
}