Create Custom Attributes and Assign Values from CSV File
One of my customer asked a way to create Custom Attributes on vCenter Server and assign values from the csv file. They have couple of vCenter Servers with thousands of VMs which makes really hard to create and assign values to Custom Attributes. So, I prepared a PowerCLI script that connects to the provided vCenter Server, creates custom attributes if they don’t already exist, imports a csv file and applies custom attributes to VMs as specified in the csv file. While doing this it logs actions and errors to a timestamped log file. It also supports a report mode where no actual changes made but a detailed report is generated.
You can download the script from https://github.com/mhakancan/create-custom-attributes-with-csv. Please make sure all requirements below are provided before run the script.
REQUIREMENTS
- PowerShell version 7.4.3 or later.
- .NET Framework version 4.8 or later.
- VMware PowerCLI module installed (version 13.2.1 or later).
- Necessary permissions to manage custom attributes and virtual machines in vCenter Server.
- Encrypted credentials XML file for authentication.
- CSV file prepared in advance with the following columns:
- Server Name – Mandatory –> Virtual Machine Name
- Rest Of Custom Attributes will be identified by the given csv file
Note: The use of this script and any issues that may arise after the import process are the responsibility of the person executing it. It should not be forgotten that since the export operation involves making changes to the vCenter Server Database, it must be tested thoroughly and should only be attempted on a backed-up vCenter Server.
Another use case with Custom Attributes on vCenter Server is you can use those Attributes and their values to create custom dashboards or reports on Aria Operations. If you interested you should read https://www.mhakancan.com/visualizing-vms-distribution-information-dashboard-on-vrops-with-using-vcenter-custom-attributes/ that gives you ideas.
Enjoy!