So we use VM Tags in vCenter for Backup purposes using Veeam. I am working on a script that will deploy a virtual machine to vCenter, and I want to add a prompt for which VM Tag to apply to the VM as part of the process. I am trying to determine what variable or command I would use to prompt and then assign the selection to the VM.
I have the variable set as follows.
$BackupTypes = “Dev-2-Week-Linux”,“Dev-2-Week-Windows”,“Dev-4-Week-Linux”,“Dev-4-Week-Windows”,“DomainControllers”,“Prod-2-Week-Linux”,“Prod-2-Week-Windows”,“Prod-4-Week-Linux”,“Prod-4-Week-Windows”
So what I want is as part of the process when asking for VM specifics a prompt comes up asking for Backup Type (the variable I created above) and I select which tag I want and it adds it to the VM. This removes one more step I have to do post VM deployment.
Just wanted to add a bit more info concerning what else i am already requesting. #VM Notes
$ChosenNotes = Get-DeploymentVariables -Prompt “Enter VM Notes”
#Server Owner
$ChosenOwner = Get-DeploymentVariables -Prompt "Enter Server Owner"
#Server Function
$ChosenFunction = Get-UserPrompt -Options $ServerFunctions -Prompt "Choose Server Function"
#Creator
$ChosenCreator = Get-DeploymentVariables -Prompt "Enter Your Name"
#HD Event
$ChosenHDEvent = Get-DeploymentVariables -Prompt "Enter HD Event Number"
#Domain.
$ChosenDomain = Get-UserPrompt -Options ("DMZ","Internal") -Prompt "Choose Domain."
And a bit more info. Currently the script was assigning to folders based on selection. As below I need to change this to add the tag that is selected.
#Deploy VM
if($BackupTypes -eq “No Backups”){
$FolderName = $FolderPathStart+$ChosenBackup+“/”+$ChosenDivision
}
These are my tags specified.
$BackupTypes = “Dev-2-Week-Linux”,“Dev-2-Week-Windows”,“Dev-4-Week-Linux”,“Dev-4-Week-Windows”,“DomainControllers”,“Prod-2-Week-Linux”,“Prod-2-Week-Windows”,“Prod-4-Week-Linux”,“Prod-4-Week-Windows”
else {
$FolderName = $FolderPathStart+“Backup/”+$ChosenBackup+“/”+$ChosenDivision
}
Before we proceed … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
When you have to add more information or you want to correct something in your question you can go back and edit your own posts. You don’t have to add a new each time.
I don’t have experiences with vCenter and I don’t know about the cmdlets you’re using in your code. Obviously they are already able to prompt for information. How about using the same way for your purpose?
In general you can use the parameter validation PowerShell offers for function parameters. In this particular case I’d recommend to read about the [ValidateSet()] attribute.