The DSC Resources for VMware 2.1 release has taken a major step forward in the ability to manage your vSphere environments with PowerShell DSC and PowerCLI. The goal of this latest release is to be able to apply standard configuration management practices to ESXi hosts. In order to accomplish this, there are 45 new resources included as part of the VMware.vSphereDSC module. We can now manage advanced settings, datastores, firewall rules, services, vSphere Standard Switches (VSS), and much more.
Let’s check out this update in action!
In Action
To show an example of what we can do with these resources, let’s start with a freshly deployed vCenter Server which only has some basic configurations applied (eg. DNS, NTP, AD integration) and three ESXi hosts with only the root password and Management vmkernel configured. From that point, using only a configuration file and PowerShell DSC, we can stand up a vSphere environment and be ready for VMs to be deployed in a matter of minutes!
Configuration File
The configuration file we used to create all of the objects and establish their configurations uses only fourteen of the available resources along with some built-in PowerShell functionality. The code can be found here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
$configurationData = @{ AllNodes = @( @{ NodeName = 'localhost' PSDscAllowPlainTextPassword = $true PSDscAllowDomainUser = $true VCenters = @( @{ Server = 'vcsa01.corp.local' VMHUser = 'root' Password = 'VMware1!' VMHost = @('esx01.corp.local', 'esx02.corp.local', 'esx03.corp.local') VMFolder = @('Management', 'Production', 'Development') } ) } ) } Configuration vCenter_Config { Import-DscResource -ModuleName VMware.vSphereDSC Node localhost { foreach ($vCenter in $AllNodes.VCenters) { $Server = $vCenter.Server $VCUser = $vCenter.VCUser $VMHUser = $vCenter.VMHUser $Password = $vCenter.Password | ConvertTo-SecureString -asPlainText -Force $VcCreds = New-Object System.Management.Automation.PSCredential($VCUser, $Password) $VmhCreds = New-Object System.Management.Automation.PSCredential($VMHUser, $Password) Datacenter "PoShDSC_DC" { Server = $Server Credential = $VcCreds Name = 'PoShDSC' Location = [string]::Empty Ensure = 'Present' } Cluster "Production_$($Server)" { Server = $Server Credential = $VcCreds Name = 'Production' Location = [string]::Empty DatacenterName = 'PoShDSC' DatacenterLocation = [string]::Empty Ensure = 'Present' HAEnabled = $false DrsEnabled = $true DrsAutomationLevel = 'FullyAutomated' DrsMigrationThreshold = 5 DrsDistribution = 0 MemoryLoadBalancing = 100 CPUOverCommitment = 500 DependsOn = "[Datacenter]PoShDSC_DC" } foreach ($vmh in $vCenter.VMHost) { $vmhName = $vmh.split('.')[0] vCenterVMHost "vCenterVMHost_$($vmhName)" { Server = $Server Credential = $VcCreds Name = $vmh Location = 'Production' DatacenterName = 'PoShDSC' DatacenterLocation = '' Ensure = 'Present' VMHostCredential = $VmhCreds ResourcePoolLocation = '/' Port = 443 Force = $true DependsOn = "[Cluster]Production_$($Server)" } VMHostScsiLun "VMHostScsiLun_$($vmhName)_mpx.vmhba0C0T0L0" { Server = $Server Credential = $VcCreds VMHostName = $vmh CanonicalName = 'mpx.vmhba0:C0:T0:L0' BlocksToSwitchPath = 0 CommandsToSwitchPath = 0 IsLocal = $true IsSsd = $false MultipathPolicy = 'Fixed' PreferredScsiLunPathName = 'vmhba0:C0:T0:L0' } VMHostScsiLunPath "VMHostScsiLunPath_$($vmhName)_vmhba0:C0:T0:L0" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'vmhba0:C0:T0:L0' ScsiLunCanonicalName = 'mpx.vmhba0:C0:T0:L0' Active = $true Preferred = $true DependsOn = "[VMHostScsiLun]VMHostScsiLun_$($vmhName)_mpx.vmhba0C0T0L0" } VmfsDatastore "VmfsDatastore_$($vmhName)_LocalDatastore" { Server = $Server Credential = $VcCreds VMHostName = $vmh Ensure = 'Present' Name = "Local Datastore - $($vmhName)" Path = 'mpx.vmhba0:C0:T0:L0' BlockSizeMB = 1 CongestionThresholdMillisecond = 30 FileSystemVersion = '5' StorageIOControlEnabled = $false DependsOn = "[VMHostScsiLun]VMHostScsiLun_$($vmhName)_mpx.vmhba0C0T0L0" } VMHostDnsSettings "VMHostDnsSettings_$($vmhName)" { Server = $Server Credential = $VcCreds Name = $vmh Dhcp = $false DomainName = 'corp.local' HostName = $vmhName Address = @('192.168.110.10') Ipv6VirtualNicDevice = '' SearchDomain = @('corp.local') VirtualNicDevice = '' } VMHostNtpSettings "VMHostNtpSettings_$($vmhName)" { Server = $Server Credential = $VcCreds Name = $vmh NtpServer = @('192.168.110.10') NtpServicePolicy = 'Automatic' } VMHostService "VMHostService_TSM-SSH_$($vmhName)" { Server = $Server Credential = $VcCreds Name = $vmh Key = 'TSM-SSH' Policy = 'On' Running = $true } VMHostPhysicalNic "VMHostPhysicalNic_$($vmhName)_vmnic0" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'vmnic0' BitRatePerSecMb = 10000 Duplex = 'Full' } VMHostPhysicalNic "VMHostPhysicalNic_$($vmhName)_vmnic1" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'vmnic1' BitRatePerSecMb = 10000 Duplex = 'Full' } StandardSwitch "StandardSwitch_$($vmhName)_vSwitch0" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'vSwitch0' Ensure = 'Present' Mtu = 1500 NicDevice = @('vmnic0', 'vmnic1') BeaconInterval = 1 LinkDiscoveryProtocolType = 'Unset' LinkDiscoveryProtocolOperation = 'Unset' AllowPromiscuous = $false ForgedTransmits = $true MacChanges = $true Enabled = $false CheckBeacon = $false ActiveNic = @('vmnic0', 'vmnic1') StandbyNic = @() NotifySwitches = $true Policy = 'Loadbalance_srcid' RollingOrder = $false DependsOn = "[VMHostPhysicalNic]VMHostPhysicalNic_$($vmhName)_vmnic0", "[VMHostPhysicalNic]VMHostPhysicalNic_$($vmhName)_vmnic1" } StandardPortGroup "StandardPortGroup_$($vmhName)_Management" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'Management' VssName = 'vSwitch0' Ensure = 'Present' VLanId = 0 LoadBalancingPolicy = 'Unset' ActiveNic = @('vmnic0') StandbyNic = @() UnusedNic = @('vmnic1') NetworkFailoverDetectionPolicy = 'Unset' DependsOn = "[StandardSwitch]StandardSwitch_$($vmhName)_vSwitch0" } StandardPortGroup "StandardPortGroup_$($vmhName)_Storage" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'Storage' VssName = 'vSwitch0' Ensure = 'Present' VLanId = 1700 LoadBalancingPolicy = 'Unset' ActiveNic = @('vmnic1') StandbyNic = @() UnusedNic = @('vmnic0') NetworkFailoverDetectionPolicy = 'Unset' DependsOn = "[StandardSwitch]StandardSwitch_$($vmhName)_vSwitch0" } StandardPortGroup "StandardPortGroup_$($vmhName)_VM Network" { Server = $Server Credential = $VcCreds VMHostName = $vmh Name = 'VM Network' VssName = 'vSwitch0' Ensure = 'Present' VLanId = 1731 LoadBalancingPolicy = 'Unset' ActiveNic = @('vmnic0', 'vmnic1') StandbyNic = @() UnusedNic = @() NetworkFailoverDetectionPolicy = 'Unset' DependsOn = "[StandardSwitch]StandardSwitch_$($vmhName)_vSwitch0" } } foreach ($folder in $vCenter.VMFolder) { Folder "Folder_$($folder)" { Server = $Server Credential = $VcCreds Name = $folder Location = '' DatacenterName = 'PoShDSC' DatacenterLocation = '' Ensure = 'Present' FolderType = 'VM' DependsOn = "[Datacenter]PoShDSC_DC" } Folder "Folder_$($folder)_Windows" { Server = $Server Credential = $VcCreds Name = 'Windows' Location = $folder DatacenterName = 'PoShDSC' DatacenterLocation = '' Ensure = 'Present' FolderType = 'VM' DependsOn = "[Folder]Folder_$($folder)" } Folder "Folder_$($folder)_Linux" { Server = $Server Credential = $VcCreds Name = 'Linux' Location = $folder DatacenterName = 'PoShDSC' DatacenterLocation = '' Ensure = 'Present' FolderType = 'VM' DependsOn = "[Folder]Folder_$($folder)" } } Folder Folder_Management_VMware { Server = $Server Credential = $VcCreds Name = 'VMware' Location = 'Management' DatacenterName = 'PoShDSC' DatacenterLocation = '' Ensure = 'Present' FolderType = 'VM' DependsOn = "[Folder]Folder_Management" } } } } vCenter_Config -ConfigurationData $configurationData |
For more information about each of the resources and some sample configurations, see the GitHub repository: DSC Resources for VMware Documentation
Summary
The DSC Resources for VMware 2.1 release has taken a major step forward in the ability to manage your vSphere environments with PowerShell DSC and PowerCLI. There are now more than 60 resources which give the ability to use configuration management concepts and apply them to our vSphere environments. This post showed how we could go from an empty vCenter Server to a workload ready vSphere environment in a matter of minutes with the latest set of resources.
Download the latest VMware.vSphereDSC module from the PowerShell Gallery today, and let us know in the comments how you’re using it in your environment!
For more information about the DSC Resources for VMware 2.1 release, see: New Release – DSC Resources for VMware 2.1