This repository purpose is to gather multiple scripts to help automating VMware vSphere infrastructures management.
Most of the automation is build around VMware Tags. For example VMs could be added or removed from DRS groups depending of there tags. The same goes for SPBM management.
List of the available scripts:
Each sub folder is an independant script. All of them are designed with the same pattern that has been inspired by Brandon Olin blog post https://devblackops.io/building-a-simple-release-pipeline-in-powershell-using-psake-pester-and-psdeploy/.
- Powershell (tested with version 5)
- Powercli (tested with version 6.5)
- Powershell modules Pester, PSake and PSScriptAnalyzer
- Download the repository from GitHub
- Unblock the archive
- Extract the archive wherever you want
- In each sub folder:
- Modify .\Configs\Config.ps1 according to your infrastructure
- If needed, modify .\Data*.csv files
- Run the script
# prechecks tests only
> .\TagsAutomatedMgmt\Build.ps1
# run the full script
> .\TagsAutomatedMgmt\Build.ps1 -Task All
This script will manage VM's tags affectation from a CSV file. It's useful when some mandatory tags have to be assign to VMs. The CSV file is the source of truth for those specifics tags. Any manual modification of this tags will be overwritten by the script.
Before using this script, you will need to modify those files:
- .\Configs\Config.ps1
- .\Data\Tags.csv
- Categories and tags have to be created before running the script
- All VM needs to be listed in the CSV file otherwise precheck test will throw an error.
# Mandatory tag's categories that have to be assign to VMs
# Those categories have to be created before running the script
$cfg.category = @(
'Datacenter',
'Replication'
)
This script will manage DRS VM's groups. VMs are added or removed depending on the tags associated to it.
Before using this script, you will need to modify those files:
- .\Configs\Config.ps1
- Categories have to be created before running the script
- DRS VM groups have to be created before running the script.
- VM Groups should contains at least two VMs otherwise the script will throw an error if it has to removed a VM from a group with only one VM.
# Category where to look at tags associated to DRS VM Group
$cfg.TagCategory = 'Datacenter'
# Tag associated to DRS VM group
# 1 Tag = 1 DRS VM group
$cfg.TagDRSGroup = @(
@{'DC01' = 'VM-DC01'},
@{'DC02' = 'VM-DC02'}
)
This script will manage Storage Policy affectation to VMs based on tags. The script will compare tags assign to the VM with tags used in SPBM rule-sets.
Before using this script, you will need to modify those files:
- .\Configs\Config.ps1
- SPBM should have been created first before running the script.
- SPBM Rule-Set should use the same tags than the VMs
# Tag categories used by the Storage Policies and VMs
$cfg.TagCategory = @(
'Datacenter',
'Replication'
)
This script will invoke a Storage vMotion to move VMs to a compliant datastore. If multiple datastore are compliants, the one with higher free space is selected.
Before using this script, you will need to modify those files:
- .\Configs\Config.ps1
- SPBM should have been created first before running the script.
Erwan Quélin
- Brandon Olin for his blog post about Powershell release pipeline.
- Luc Deckens and Matt Boren for the DRSRule module used in GRSGroupsAutomatedMgmt script.