Close Menu
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn X (Twitter) Facebook
PowerShell.roPowerShell.ro
  • Home
  • Automation
  • Powershell
  • VMWare
  • Windows
LinkedIn Facebook X (Twitter)
PowerShell.roPowerShell.ro
Home»Automation»Tagging Virtual Machines with the CISTag Module in PowerShell
Automation

Tagging Virtual Machines with the CISTag Module in PowerShell

Catalin CristescuBy Catalin CristescuFebruary 1, 2024
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email

In this blog post, we’ll explore the process of assigning tags to multiple VMs using the CIStag module in PowerShell. This becomes necessary when the conventional PowerCLI module for tagging VMs fails, as was the case for me.

Discovering a solution in a VMware blog post (https://blogs.vmware.com/PowerCLI/2018/12/new-tag-management-module.html), I learned about the CIStag module for effective VM tag management. After downloading and installing the module on my Windows server, I proceeded to utilize it for assigning tags to VMs.

The script provided in this post is specifically designed to establish a connection with a vCenter server, extract a list of VMs from the input file, and then assign the appropriate tags.

The VMware.Community.CISTag module enhances vSphere tag management by leveraging the vSphere REST API for improved automation. With functions like tag gathering, assignment, and removal, it addresses challenges in larger environments. Notable performance improvements, such as a 25% speed boost in environments with 400 tags, make it a valuable resource. Downloadable from the PowerCLI Community Repository, the module also exhibits increased reliability, overcoming common issues like timeout errors. Users are encouraged to explore and share their experiences with this powerful tool.

The script:

The script is designed to connect to a vCenter server, get list of VMs from the input file and assign the tag.

# Import required modules
Import-Module -Name VMware.Community.CISTag
Import-Module -Name VMware.VIMAutomation.Cis.Core

# Get vCenter Server credentials
$VCSACreds = Get-Credential

# Connect to vCenter Server
Connect-CisServer -Server VCSA_FQDN -Credential $VCSACreds

# Read VM names from input file
$vms = Get-Content -Path "input_file.txt"

# Specify the tag to be assigned
$TAGName = "No Job"

# Loop through each VM and assign the tag
foreach ($VM in $vms) {
    Write-Host "Configuring 'No Job' tag for $VM"
    New-CISTagAssignment -Tag (Get-CISTag -Name $TAGName).Name -Entity $VM 
    Write-Host "Configuration completed for $VM"
}

# Disconnect from vCenter Server
Disconnect-CisServer -Server VCSA_FQDN -Confirm:$false

CISCore CISTAG Get-CISTag modify vm tag New-CISTagAssignment powercli vcenter vm tag management vm tags
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleUpdate HPE ILO firmware using PowerShell
Next Article vExperts stats 2024
Catalin Cristescu
  • Website

Related Posts

Automation

PowerShell script for automated remediation for CrowdStrike issue

July 20, 2024
VMWare

vExperts stats 2024

May 27, 2024
Powershell

Update HPE ILO firmware using PowerShell

January 2, 2024

Comments are closed.

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
Categories
  • Automation (11)
  • Powershell (14)
  • Uncategorized (1)
  • VMWare (15)
  • Windows (2)
About Powershell.ro

Powershell.ro, the ultimate hub for tech enthusiasts! Dive into expert-written articles on PowerShell scripts, VMware, automation, Microsoft technologies, and DevOps practices. Unlock tips, tutorials, and solutions designed to empower IT professionals and boost your skills in automation and infrastructure management.

Recent Posts
  • PowerShell script for automated remediation for CrowdStrike issue
  • vExperts stats 2024
  • Tagging Virtual Machines with the CISTag Module in PowerShell
  • Update HPE ILO firmware using PowerShell
  • PowerCLI script to check Cluster Overcommitment ratio
LinkedIn
© 2025 PowerShell.ro.

Type above and press Enter to search. Press Esc to cancel.