Automate PowerCLI Install across your Windows Environment using PowerShell DSC

Automate PowerCLI Install across your Windows Environment using PowerShell DSC

Automate PowerCLI Install using PowerShell DSC

I have some cool stuff to share today, I was exploring the various internal DSC resources in the past week, and something which caught my eye was the “Package” DSC resource module.

Automate PowerCLI

What this module really allows you to do is to automate the configuration deployment of packages across your organization. During my DSC testing i was trying to install various packages on servers using this resource module.

Then finally it struck me why cant i Automate PowerCLI binary install itself.

One great thing i was able to achieve was to Automate PowerCLI binaries install across my windows test environment, it feels really awesome when you see that “It Just Works!”

To learn more about DSC, head over to the Windows PowerShell Team Blog, Blog 2.

You also need to have WMF 4.0 / WMF 5.0 installed on your servers for DSC to work.

Now lets get into how i achieved it.

Note :- In my test setup i had a set of 4 vm’s running on vSphere 6.0, all the servers are Windows 2012 R2 and have PowerShell v4 in them.

automate powercli

Now let’s explore the list of readily available resources which come by default.

To get them you will need to run a Get-DSCResource in the powershell console.

automate powercli

As you can see we have the package and the file resource, we would be using both these resources for our DSC configuration.

Also you will need to configure winrm on the test machines, you can do this by executing the below command on the powershell console and also remember to accept the defaults.

winrm qc

Next to start off with our script, we will need to copy over the powercli binary VMware-PowerCLI-6.0.0-3205540.exe to a share location, in my test setup i copied it over to c:\ drive of the push server ( from where the configurations are being pushed)

automate powercli

 

This is the location which would be used by the File resource to copy over the binary to the servers if they are non existent.

Next let me walk through the DSC configuration to install the package, i have updated comments for each and every step.

# Creating the configuration called InstallPowerCLI
Configuration InstallPowerCLI {

# Assigning the computername parameter so that this resource can be invoked across multiple servers.
param (
[String[]]$ComputerName
)

Node $ComputerName {

<# Below we create the file resource which makes sure that the install exe file is copied .
over to the destination servers, in below example we need to make sure we have c:\dsc scripts
location existing in the servers, also the condition Ensure = "Present" make's sure that
if the file does not exist it gets copied over to the location and if the files are found to be
existing they are not copied over #>

File CopyPowerCLIFile {
        DestinationPath = "c:\dsc scripts\VMware-PowerCLI-6.0.0-3205540.exe"
        SourcePath = "\\VinithPSTest\SMB\VMware-PowerCLI-6.0.0-3205540.exe"
        Ensure = "Present"
        Type = "File"
        
        }

<# Below we create the Package resource which goes ahead and install's powercli across the
destination servers, we perform a silent install of powercli on the destination servers using 
the specified set of arguments, we will also need to mention the ProductId of the server.

Also note that we have a DependsOn condition set to "[File]CopyPowerCLIFile", this condition ensures
that the destination location from which the powercli package gets installed consists of the 
exe file or else the installation configuration would not proceed.#>

<#

# The product ID for PowerCLI can be obtained using the below command
Get-WMIObject Win32_Product | ?{$_.name -match "VMware vSphere PowerCLI"} | Format-Table IdentifyingNumber, Name, LocalPackage

IdentifyingNumber                      Name                    LocalPackage
-----------------                      ----                    ------------
{EE5ADC6C-37FA-4E52-8F14-7D7703D64463} VMware vSphere PowerCLI C:\Windows\Installer\94360c7.msi

#>
Package PowerCLI {
Name = "VMware vSphere PowerCLI"
Path = "C:\dsc scripts\VMware-PowerCLI-6.0.0-3205540.exe"
Arguments = '/b"C:\Windows\Temp" /VADDLOCAL=ALL /S /V"/qn ALLUSERS=1 REBOOT=ReallySuppress"'
ProductId = "EE5ADC6C-37FA-4E52-8F14-7D7703D64463"
Ensure= "Present"
DependsOn = "[File]CopyPowerCLIFile"
}

}
}

Next once we have the configuration ready, lets create the MOF files which would be pushed across the three servers.

We can get them by invoking the configuration we created.

InstallPowerCLI -ComputerName VinithDSCTestWi,VinithDSCTest-0,VinithDSCTest-1 -OutputPath C:\SMB

automate powercli

Next lets use the Start-DscConfiguration cmdlet to apply the configuration to nodes. This would be the Push mode of applying the configuration, we can also go for a Pull mode if we have a larger environment.

Start-DscConfiguration -Wait -Force -Verbose -Path C:\SMB

Once we invoke this command, the configurations will start getting applied on the destination servers,

automate powercli

automate powercli

You can also run the Get-DSCConfiguration on each individual server to get the status of configurations applied on the server

automate powercli

The end result is what we all have been waiting for, and its fantastic :), you would see powercli installed on all the three servers.

Here’s a view from Add Remove Programs from one of the server where the configuration got applied.

automate powercli

Now moving own, let’s dig deep into more advanced DSC, my next blog post talks about a custom DSC resource built to manage snapshots using PwerCLI

I hope you enjoyed this blog post on Automate PowerCLI install using DSC with VMware and found the information useful.

Do Check out my other posts on DSC and PowerCLI

Share this post

2 thoughts on “Automate PowerCLI Install across your Windows Environment using PowerShell DSC

Post Comment