Worklet: Install Skype on Windows

Installs Skype on Windows

Evaluation code:

#REQUIRES -Version 2.0
<#
.SYNOPSIS
    This Test script checks to see if Skype is installed
.DESCRIPTION
    This script queries the installed files for 32 and 64bit software
    and returns a 0 if product is installed or 1 if not
.Notes
    File Name       :Skype_Install_Test.ps1
    Author          :Automox
    Prerequisite    :PowerShell V2 over win7 and upper
#>
#Handle Exit Codes:
trap {  $host.ui.WriteErrorLine($_.Exception); exit 90 }

function Skype_Install_Test {
    <#
    .SYNOPSIS
        This function Checks for the Skype is Installed on system or not .
    .DESCRIPTION
        After checking the Skype availability, based on the exit code tool will decide to call remediation code or not.
    .EXAMPLE
        Skype_Install_Test
    .NOTES
    #>

    # Application Name which is to be installation verified.
    $appName = 'Skype'
    # Finding the Systen Directory (system32 Directory).
    $sysDir = [Environment]::SystemDirectory

    # Making the 32 bit and 64 bit path names blank.
    $32BIT = ""
    $64BIT = ""

    #Get Registry value for the 32 bit software installed on both 32-bit and 64-bit machine
    Try {  $32BIT = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' -ErrorAction Stop |
           Select-Object DisplayName |
           Select-String "$appName" |
           Out-String
    }
    Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;
            Write-Output $Exception
            exit 90
    }
    # Script blcok to execute with powershell
    # Match name in the block should be hard coded.
    $scriptBlock = {$key = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' |
                        Where-Object { $_.DisplayName -match 'Skype'}
                        return $key
                    }

    # Get the Registry value for the 64 bit software installed on the 64 bit machine. as the automox process is 32 bit
    if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "64-bit")
    {
        # Call for accessing the 64 bit registry incase 32 bit process not access the registry.        
		Try
		{
			$installed64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)
			$64BIT = $installed64.DisplayName
		}
		Catch
		{
			$Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber;
			Write-Output $Exception
			exit 90
		}
        
    } elseif ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -eq "32-bit") {
        # Checking for the 64 bit registry on 32 bit host.
        # In Script block line 38 match name should be hard coded and it should be proper.
        Try {
            $installed64 = @(& "$sysDir\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock)
            $64BIT = $installed64.DisplayName
        }
        Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber
                Write-Output $Exception
                exit 90
        }
    }

    # Check for the Availability of the software and exit with relevent exit code.
    if ($32BIT.Trim() -match $appName -or ($64BIT -ne $null -and $64BIT.Trim() -match $appName)) {
        #Application Found, Automox can handle the updates!
        exit 0
    } else {
        # Application is not installed! Run Remediation Script to install it.
        exit 1
    }
}

Skype_Install_Test

Remediation code:

#REQUIRES -Version 2.0
<#
.SYNOPSIS
    This script allows an admin to install Skype
.DESCRIPTION
    This script downloads the quiet exe installer into /Temp and runs it.
    Once the script has executed it will remove the install files
    This is an example script that has been tested to work on Win10 and Win7.
    This script may not work on all systems. Modify to fit your needs
.NOTES
    File Name       :Skype_Install.ps1
    Author          :Automox
    Prerequisite    :PowerShell V2 over win7 and upper
.LINK
    http://www.automox.com
#>

#Handle Exit Codes:
trap {  $host.ui.WriteErrorLine($_.Exception); exit 90 }

function Skype_Install_Rem {

    <#
    .SYNOPSIS
        This function allows automox to Install the Skype on Windows .
    .DESCRIPTION
        This function download and installs the latest version of Skype on system.
    .EXAMPLE
        Skype_Install_Rem
    .NOTES
    #>

    #############Change the settings in this block#######################
    # Skype installer download local system path.
    $saveFilePath = "$PSScriptRoot\Skype_Install.exe"

    # URL for skype installer
    $URL="http://www.skype.com/go/getskype-full"
    #####################################################################

   # Creating the web client object
    $downloader = New-Object -TypeName System.Net.WebClient
    # Download skype installer
    Write-Output "Downloading Skype...`n"
    Try {$downloader.DownloadFile("$URL", "$saveFilePath")
        Write-Output "Download Finished...Installing Skype...`n"
    }
    Catch { Write-Output "File download failed. Check URL [$URL] and try again."
            Exit 90
    }

    # Install the installer
    # Removed -Wait command as it is taking lot of time and do loop will take care of the installer file deletion.
    Try {$process = Start-Process -FilePath "$saveFilePath" -ArgumentList " /qn /VERYSILENT /SP- /NOCANCEL /NORESTART /SUPPRESSMSGBOXES /NOLAUNCH" -PassThru -ErrorAction Stop
         Write-Output "Skype Install Finished...`n"
    }
    Catch { $Exception = $error[0].Exception.Message + "`nAt Line " + $error[0].InvocationInfo.ScriptLineNumber
            Write-Output $Exception
            exit 90
    }

    # Avoid error while deleting the installer as process of installation is in progress.
    do {
        if ((Get-Content $saveFilePath)) {
            Write-Output "Installer complete...cleaning up installation files"
            Remove-Item -force "$saveFilePath" -ErrorAction SilentlyContinue
            exit $process.ExitCode
        } else {
            Write-Output "Waiting for Installer File Unlock"
        }
        $fileunlocked = 1
    }	Until ($fileunlocked)
}

Skype_Install_Rem