Wednesday, September 2, 2015

Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)

Multiple ways to Install software remotely
Multiple ways to Install Software remotely on Windows - Method 1 Group Policy
Multiple ways to Install Software remotely on Windows - Method 2 Third party softwares

Multiple ways to Install Software remotely on Windows - Method 3 Command line PSEXEC tool
Multiple ways to Install Software remotely on Windows - Method 4 WMI (Windows Management Instrumentation)
Multiple ways to Install Software remotely on Windows - Method 5 PowerShell Remoting
Multiple ways to Install Software remotely on Windows - Method 6 PowerShell DSC (Desired State Configuration)
Multiple ways to Install Software remotely on Windows - Method 7 Copy Portable applications
Multiple ways to Install Software remotely on Windows - Method 8 Task scheduler 

DSC (Desired state configuration) is a very cool method of performing task remotely. I am seeing over the period Microsoft is evolving it script technology to make life more hassle free.

What is DSC (Desired State configuration)?
In my words DSC uses WS-Management protocol (WinRM) it made to push configuration on remote server or pull information from DSC server.  (To see how i enabled WinRM service please check my blog Method 5 PowerShell Remoting) Once you run DSC command you are telling remote computer that its configuration must be according what I have defined. In simple terms It is same as Group Policy.
Prerequisite to use DSC is your computers should have at least powershell Version 4. They are by default there on windows 2012 and windows 8 and above. Next, Make sure your applications are kept on Shared drive, This is another requirement. Here script ps1 execution is required so we need to unrestrict them inside PowerShell.

Open Powershell with run as administrator and command, This need to be run on the server from where you will be pushing Softwares to remote servers.
Set-ExecutionPolicy unrestricted -force

Before going forward, every software has some productID and it is necessary for deployment, without productid you will get error but softwares installation will not fail, so for error free, here I am showing trick to find product id for any software on windows. Install software on any windows machine (as this is a Java demo, I have installed it my one of the server), Open powershell  and fire up command 
Get-WmiObject -Query "Select Name, Caption, IdentifyingNumber from Win32_product Where Name Like 'Java%'"
It will find all the products names starting with Java and the very next is Identifyingnumber is a product ID.
Next all scripts are stored on c:\temp file below script (From this server i will be pushing software remotly) I have saved it as javainstall.ps1.


Configuration JavaInstallation {
    param ($ComputerName)
    Node $ComputerName {
        Package InstallJAVA {
            Ensure = "Present"
            Name = "Install JAVA"
            Path = "\\AD001\Softwares\JAVAInstallation\jre-8u60-windows-i586.exe"
            Arguments = "/s"

            ProductID = "26A24AE4-039D-4CA4-87B4-2F83218060F0"
        }
    }
}
JavaInstallation -ComputerName AD002


As you can see above I am in c:\temp directory JAVAinstall.ps1 and only the content marked in orange you will need to change accordingly, (Setup path and Argument). The computer name must be netbios name not the IP.

Next open powershell, change directory to c:\temp (cd c:\temp). and execute ps1 file .\JAVAinstall.ps1.
Once you execute it will create folder in same directory and mof file under it for the remote servesr (MOF file will contain all the configuration required to configure remote server) If you have assigned multiple server names in the script it will create each mof file for each server with its respective name.
Now everything is ready, we just need to push file with command Start-DSCConfiguration. 
Start-DSCConfiguration c:\temp\JavaInstallation -Wait
it is pushing all the mof files from c:\temp\javainstallation location now. 
To view results simply check installed programs on remote server.
Next method is setup copy method, cool method for installing portable setup files. go ahead check yourself Method 7 Copy Portable applications Install software remotely.
Post a Comment