Skip to content
Discussion options

You must be logged in to vote

Found a way to add tags and preserve old tags:
$VirtualMachinesPath = "/virtualization/virtual-machines/"
$BaseURI = "YOUR API URL without trailing /"

  1. Find the ID of wanted tag
    $MyTag ="Production"
    $TagID = (Invoke-RestMethod -Uri "https://$($BaseUrl)/api/extras/tags/?name=$MyTag" -Headers $headers).results.id

3.Find VM and check if existing tags contains wanted tag. If not add
$ResponseVM = Invoke-RESTMethod -Method GET -Headers $Headers -URI "$($URIBase)$($VirtualMachinesPath)cf_vmid=$($VM.VMId)"
#placeholder for updates and tags
$VMInfo = @{}
$Tags = @()
#prefill wanted tag
$Tags+= $TagID
# Check if already tagged with wanted tag. If not, update $VMInfo (keeping other tags that mi…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by AndreasMoe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants