Good afternoon,
I recently created a PowerShell script to automate and test PowerCLI scripts before running them on vCenters/ESXi hosts.
At the moment, I use a validate set to let the user chose on which server/cluster they want to execute their scripts:
param(
[string]$script = "help",
[ValidateSet("localhost", "Server1", "Server2")]
[string]$server,
[ValidateSet("DC0_C0", "DC0_C1", "DC0_C2", "Customer1")]
[string[]]$cluster,
[switch]$help
)
The issues, is that sometimes when you have big customers, probably they have multiple clusters and it would be more convenient to simply type "customer1" and have the script run on cluster1/2 and 4 instead of manually typing all the clusters:
./viexec vminfo localhost Cluster1,Cluster3,Cluster10
./viexec vminfo localhost Customer1 #And have the script run automatically on all the right clusters.
I already tried using an if that checks the value of the variable $cluster and if it equals "Customer1" then it replace his value with the appropriate clusters, but I don't find this solution elegant. And it's hard to configure/maintain, since the user would need to modify the code, so even better if those parameters could be created from an external config file/user input.
I was also wondering if it was possible to retrieve the param of the validateset from a file/csv to avoid users to customize the main script.ps1, but instead simply replace/write their servers and clusters in a .CSV that populates the validateset parameter.
Hope it is clear..
Regards, Alessandro