Created
May 16, 2016 13:52
-
-
Save Hexalon/412c4b07693bd3021b89b969d3bd545c to your computer and use it in GitHub Desktop.
Automates installation of Skype For Business 2015
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.NOTES | |
=========================================================================== | |
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.119 | |
Created on: 5/3/2016 09:37 | |
Created by: Colin Squier <[email protected]> | |
Filename: Install-SkypeForBusiness2015.ps1 | |
=========================================================================== | |
.DESCRIPTION | |
Automates installation of Skype For Business 2015. | |
#> | |
[CmdletBinding()] | |
Param ( | |
[switch]$Uninstall = $false | |
) | |
function Get-ScriptDirectory | |
{ | |
if ($HostInvocation -ne $null) | |
{ | |
Split-Path $HostInvocation.MyCommand.path | |
} | |
else | |
{ | |
Split-Path $script:MyInvocation.MyCommand.Path | |
} | |
} | |
function RemoveOldVersions | |
{ | |
Write-Verbose -Message "Uninstalling old versions of Communicator/Lync/Skype for Business" | |
$Lync = (Get-Process -Name lync -ErrorAction SilentlyContinue) | |
if (!($Lync -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name lync -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the lync process." | |
} | |
until ((Get-Process -Name lync -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
$Communicator = (Get-Process -Name communicator -ErrorAction SilentlyContinue) | |
if (!($Communicator -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name communicator -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the communicator process." | |
} | |
until ((Get-Process -Name communicator -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
$Outlook = (Get-Process -Name outlook -ErrorAction SilentlyContinue) | |
if (!($Outlook -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name outlook -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the outlook process." | |
} | |
until ((Get-Process -Name outlook -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
# Communicator 2007 | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{E5BA0430-919F-46DD-B656-0796F8A5ADFF}") | |
{ | |
Write-Verbose -Message "Removing Communicator 2007" | |
Start-Process "msiexec.exe" -ArgumentList "/X `"{E5BA0430-919F-46DD-B656-0796F8A5ADFF}`" /qn /norestart" -Wait | |
} | |
# Lync 2010 | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{81BE0B17-563B-45D4-B198-5721E6C665CD}") | |
{ | |
Write-Verbose -Message "Removing Lync 2010" | |
Start-Process "msiexec.exe" -ArgumentList "/X `"{81BE0B17-563B-45D4-B198-5721E6C665CD}`" /qn /norestart" -Wait | |
} | |
# Lync 2013/2015 64-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC") | |
{ | |
Write-Verbose -Message "Removing Lync 2013/Skype for Business 2015 64-bit" | |
Copy-Item $FullPathUninstall -Destination "$env:CommonProgramFiles\Microsoft Shared\OFFICE15\Office Setup Controller" -Force | |
Start-Process "$env:CommonProgramFiles\Microsoft Shared\OFFICE15\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
# Lync 2013/2015 32-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC") | |
{ | |
Write-Verbose -Message "Removing Lync 2013/Skype for Business 2015 32-bit" | |
Copy-Item $FullPathUninstall -Destination "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE15\Office Setup Controller" -Force | |
Start-Process "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE15\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
# Skype 2016 32-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90160000-012B-0409-0000-0000000FF1CE}") | |
{ | |
Write-Verbose -Message "Removing Skype for Business 2016 32-bit" | |
Copy-Item $FullPathUninstall -Destination "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE16\Office Setup Controller" -Force | |
Start-Process "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE16\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
# Skype 2016 64-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90160000-012B-0409-1000-0000000FF1CE}") | |
{ | |
Write-Verbose -Message "Removing Skype for Business 2016 64-bit" | |
Copy-Item $FullPathUninstall -Destination "$env:CommonProgramFiles\Microsoft Shared\OFFICE16\Office Setup Controller" -Force | |
Start-Process "$env:CommonProgramFiles\Microsoft Shared\OFFICE16\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
} | |
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` | |
[Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" | |
Break | |
} | |
$Option = New-CimSessionOption -Protocol Dcom | |
$Session = New-CimSession -SessionOption $Option -ComputerName $env:COMPUTERNAME | |
$OS = (Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $Session) | |
$ScriptDirectory = Get-ScriptDirectory | |
$File = "setup.exe" | |
$ConfigFile = "lync.ww\config.xml" | |
$UninstallFile = "UninstallLync.xml" | |
$Product = "Skype For Business 2015" | |
Write-Verbose -Message "-= $Product installation script =-" | |
$FullPath = Join-Path -Path $ScriptDirectory -ChildPath "x86\$File" | |
$FullConfigPath = Join-Path -Path $ScriptDirectory -ChildPath "x86\$ConfigFile" | |
$FullPathUninstall = Join-Path -Path $ScriptDirectory -ChildPath $UninstallFile | |
Write-Verbose -Message "Full path to install file $FullPath" | |
Write-Verbose -Message "Full path to config file $FullConfigPath" | |
if ($Uninstall) | |
{ | |
$Lync = (Get-Process -Name lync -ErrorAction SilentlyContinue) | |
if (!($Lync -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name lync -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the lync process." | |
} | |
until ((Get-Process -Name lync -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
$Communicator = (Get-Process -Name communicator -ErrorAction SilentlyContinue) | |
if (!($Communicator -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name communicator -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the communicator process." | |
} | |
until ((Get-Process -Name communicator -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
$Outlook = (Get-Process -Name outlook -ErrorAction SilentlyContinue) | |
if (!($Outlook -eq $null)) | |
{ | |
do | |
{ | |
Stop-Process -Name outlook -Force -ErrorAction SilentlyContinue | |
Write-Verbose -Message "Killing the outlook process." | |
} | |
until ((Get-Process -Name outlook -ErrorAction SilentlyContinue).HasExited -eq $true) | |
} | |
# Lync 2013/2015 64-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC") | |
{ | |
Write-Verbose -Message "Removing Lync 2013/Skype for Business 2015 64-bit" | |
Copy-Item $FullPathUninstall -Destination "$env:CommonProgramFiles\Microsoft Shared\OFFICE15\Office Setup Controller" -Force | |
Start-Process "$env:CommonProgramFiles\Microsoft Shared\OFFICE15\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
# Lync 2013/2015 32-bit | |
IF (Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC") | |
{ | |
Write-Verbose -Message "Removing Lync 2013/Skype for Business 2015 32-bit" | |
Copy-Item $FullPathUninstall -Destination "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE15\Office Setup Controller" -Force | |
Start-Process "${env:CommonProgramFiles(x86)}\Microsoft Shared\OFFICE15\Office Setup Controller\Setup.exe" -ArgumentList "/uninstall LYNC /config `"UninstallLync.xml`"" -Wait | |
} | |
break; | |
} | |
Write-Verbose -Message "Checking for Office installation" | |
$Office = (Get-ItemProperty "HKLM:\Software\microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.DisplayName -match "Microsoft Office Professional Plus \d{4}" }) | |
if ($Office -eq $null -and $($OS.OSArchitecture) -eq "64-bit") | |
{ | |
Write-Verbose -Message "64-bit OS detected" | |
$Office = (Get-ItemProperty "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | Where-Object { $_.DisplayName -match "Microsoft Office Professional Plus \d{4}" }) | |
} | |
foreach ($Install in $Office) | |
{ | |
$OfficePath = $Install.PSPath | |
if ($OfficePath -match "Office14.PROPLUS") | |
{ | |
Write-Verbose -Message "Office path is $OfficePath, detecting correct Office install." | |
$Office = $Install | |
$O14Bitness = Get-ItemProperty "HKLM:\Software\Microsoft\Office\14.0\Outlook" | |
$O14Bitness = $O14Bitness.Bitness | |
Write-Verbose -Message "Office bitness is $O14Bitness" | |
} | |
if ($OfficePath -match "Office15.PROPLUS") | |
{ | |
Write-Verbose -Message "Office path is $OfficePath, detecting correct Office install." | |
$Office = $Install | |
$O15Bitness = Get-ItemProperty "HKLM:\Software\Microsoft\Office\15.0\Outlook" | |
$O15Bitness = $O15Bitness.Bitness | |
Write-Verbose -Message "Office bitness is $O15Bitness" | |
} | |
if ($OfficePath -match "Office16.PROPLUS") | |
{ | |
Write-Verbose -Message "Office path is $OfficePath, detecting correct Office install." | |
$Office = $Install | |
$O16Bitness = Get-ItemProperty "HKLM:\Software\Microsoft\Office\16.0\Outlook" | |
$O16Bitness = $O16Bitness.Bitness | |
Write-Verbose -Message "Office bitness is $O16Bitness" | |
} | |
} | |
if (!($Office -eq $null)) | |
{ | |
$InstalledVersion = $Office.DisplayVersion | |
$OfficeName = $Office.DisplayName | |
Write-Verbose -Message "Installed $OfficeName version is $InstalledVersion" | |
if ($($OS.OSArchitecture) -eq "64-bit") | |
{ | |
if (($O14Bitness -eq "x64") -or ($O15Bitness -eq "x64") -or ($O16Bitness -eq "x64")) | |
{ | |
Write-Verbose -Message "64 bit Office detected" | |
# Check for Lync 2013/2015 64-bit installation | |
if (!(Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC")) | |
{ | |
RemoveOldVersions | |
$FullPath = Join-Path -Path $ScriptDirectory -ChildPath "x64\$File" | |
$FullConfigPath = Join-Path -Path $ScriptDirectory -ChildPath "x64\$ConfigFile" | |
Write-Verbose -Message "Full path to install file $FullPath" | |
Write-Verbose -Message "Full path to config file $FullConfigPath" | |
Write-Verbose -Message "Installing 64 bit version of $Product" | |
Start-Process $FullPath -ArgumentList "/config `"$FullConfigPath`"" -Wait | |
} | |
else | |
{ | |
Write-Verbose -Message "$Product already installed, exiting." | |
} | |
} | |
else | |
{ | |
# Check for Lync 2013/2015 32-bit installation | |
if (!(Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC")) | |
{ | |
RemoveOldVersions | |
Write-Verbose -Message "Installing 32 bit version of $Product" | |
Start-Process $FullPath -ArgumentList "/config `"$FullConfigPath`"" -Wait | |
} | |
else | |
{ | |
Write-Verbose -Message "$Product already installed, exiting." | |
} | |
} | |
} | |
else | |
{ | |
# Check for Lync 2013/2015 32-bit installation | |
if (!(Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC")) | |
{ | |
RemoveOldVersions | |
Write-Verbose -Message "Installing 32 bit version of $Product" | |
Start-Process $FullPath -ArgumentList "/config `"$FullConfigPath`"" -Wait | |
} | |
else | |
{ | |
Write-Verbose -Message "$Product already installed, exiting." | |
} | |
} | |
} | |
else | |
{ | |
if ($($OS.OSArchitecture) -eq "64-bit") | |
{ | |
# Check for Lync 2013/2015 64-bit installation | |
if (!(Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC")) | |
{ | |
RemoveOldVersions | |
$FullPath = Join-Path -Path $ScriptDirectory -ChildPath "x64\$File" | |
$FullConfigPath = Join-Path -Path $ScriptDirectory -ChildPath "x64\$ConfigFile" | |
Write-Verbose -Message "Full path to install file $FullPath" | |
Write-Verbose -Message "Full path to config file $FullConfigPath" | |
Write-Verbose -Message "Installing 64 bit version of $Product" | |
Start-Process $FullPath -ArgumentList "/config `"$FullConfigPath`"" -Wait | |
} | |
else | |
{ | |
Write-Verbose -Message "$Product already installed, exiting." | |
} | |
} | |
else | |
{ | |
# Check for Lync 2013/2015 32-bit installation | |
if (!(Test-Path Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Office15.LYNC")) | |
{ | |
RemoveOldVersions | |
Write-Verbose -Message "Installing 32 bit version of $Product" | |
Start-Process $FullPath -ArgumentList "/config `"$FullConfigPath`"" -Wait | |
} | |
else | |
{ | |
Write-Verbose -Message "$Product already installed, exiting." | |
} | |
} | |
} | |
Remove-CimSession -CimSession $Session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment