Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 45 additions & 15 deletions Microsoft.AVS.Management/AVSGenericUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,46 @@ Function Convert-StringToArray {

}

Function New-AVSTag{
<#
.DESCRIPTION
This function creates or adds a tag w/ associated to an AVS Tag Category
.PARAMETER Name
Name of Tag to create or add.
.PARAMETER Description
Description of Tag. Description of existing tag will be updated if it already exists.
.PARAMETER Entity
vCenter Object to add tag to.
Comment on lines +343 to +344
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The New-AVSTag function's DESCRIPTION parameter documentation mentions an "Entity" parameter in line 343, but the function does not have an Entity parameter. The Entity parameter belongs to Add-AVSTag. Remove the Entity parameter mention from the New-AVSTag documentation.

Suggested change
.PARAMETER Entity
vCenter Object to add tag to.

Copilot uses AI. Check for mistakes.
#>

[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Name,
[Parameter(Mandatory = $false)]
[string]
$Description = "Category for AVS Operations"
Comment on lines +352 to +354
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter $Description for New-AVSTag has a default value of "Category for AVS Operations" on line 354, but this description text refers to a category, not a tag. The default description should be more appropriate for a tag, such as "AVS Operations Tag" or "Tag for AVS Operations".

Copilot uses AI. Check for mistakes.
)

# check or create AVS Tag Category
$TagCategory = Get-TagCategory -Name "AVS" -errorAction SilentlyContinue
If (!$TagCategory) {
$TagCategory = New-TagCategory -Name "AVS" -Description "Category for AVS Operations" -Cardinality:Multiple
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In New-AVSTag, the function creates a tag category with Cardinality:Multiple on line 360, but in New-AVSStoragePolicy (line 1285), the tag category is created with Cardinality Single. This inconsistency could lead to errors if one function creates the category first and the other tries to use or recreate it with different settings. Ensure both functions use the same Cardinality setting for the AVS tag category.

Suggested change
$TagCategory = New-TagCategory -Name "AVS" -Description "Category for AVS Operations" -Cardinality:Multiple
$TagCategory = New-TagCategory -Name "AVS" -Description "Category for AVS Operations" -Cardinality Single

Copilot uses AI. Check for mistakes.
}

# check or create Tag, update description if it already exists
$Tag = Get-Tag -Name $Name -Category $TagCategory -errorAction SilentlyContinue
If (!$Tag) {
$Tag = New-Tag -Name $Name -Description $Description -Category $TagCategory
} Else {
Set-Tag -Description $Description -Tag $Tag # -Category $TagCategory
}

return $Tag

}

Function Add-AVSTag{
<#
.DESCRIPTION
Expand All @@ -351,32 +391,22 @@ Function Add-AVSTag{
$Name,
[Parameter(Mandatory = $false)]
[string]
$Description,
$Description = "Category for AVS Operations",
[Parameter(Mandatory = $true)]
[VMware.VimAutomation.ViCore.Interop.V1.VIObjectCoreInterop]
$Entity
)
Begin {
$TagCategory = Get-TagCategory -Name "AVS"
If (!$TagCategory) {
$TagCategory = New-TagCategory -Name "AVS" -Description "Category for AVS Operations" -Cardinality:Multiple
}
$Tag = Get-Tag -Name $Name -Category $TagCategory
If (!$Tag) {
$Tag = New-Tag -Name $Name -Description $Description -Category $TagCategory
}
Else {Set-Tag -Description $Description -Tag $Tag}
}
$Tag = New-AVSTag -Name $Name -Description $Description
}

Process {
try {
New-TagAssignment -Tag $Tag -Entity $Entity -ErrorAction Stop
return
}
catch {
<#Do this if a terminating exception happens#>
Write-Error "Failed to assign tag '$Name' to entity '$($Entity.Name)'. Error: $_"
}

}

}
}
Loading
Loading