Skip to content

Instantly share code, notes, and snippets.

@PCfromDC
Last active November 14, 2017 20:20
Show Gist options
  • Save PCfromDC/1ec7e4630f2097a85b37 to your computer and use it in GitHub Desktop.
Save PCfromDC/1ec7e4630f2097a85b37 to your computer and use it in GitHub Desktop.
sp2016 Download Prerequisite Files
Import-Module BitsTransfer
$destPath = "C:\tempDownloads" # Change this to desired download destination path
$destPath = $destPath.TrimEnd('\')
#region validate download path
function validatePath($destFolder){
## Check that the path entered is valid
If (!(Test-Path $destFolder -Verbose)) {
New-Item -Path $destFolder -ItemType Directory
}
}
#endregion
#region start downloading files
function downloadFiles($urlList, $location) {
# Downloads files based off of $urlList array and saves them to the location based off $location
# This sets the $destFolder variable based off $location
if ($location -eq "SPPR") {$destFolder = $destPath + "\SharePoint\downloads\prerequisiteinstallerfiles"}
# Validate if path exists
validatePath -destFolder $destFolder
# Out-File path for later use...
$destFolder | Out-File "$destPath\sp2016preReqPath.txt" -Force
ForEach ($url in $urlList) {
## Get the file name based on the portion of the url after the last slash
$destFileName = $url.Split('/')[-1]
$destination = "$destFolder\$destFileName"
Try {
## Check if destination file already exists
If (!(Test-Path $destination)) {
## Begin download
Write-Host("Downloading " + $url)
Start-BitsTransfer -Source $url -Destination $destination -DisplayName "Downloading `'$destFileName`' to $destFolder" -Priority High -Description "From $url..." -ErrorVariable err
If ($err) {Throw ""}
}
Else {
# If file does exist is it WCF 5.6?
Write-Host " - File $destFileName already exists, skipping..."
}
}
Catch {
Write-Warning " - An error occurred downloading `'$destFileName`'" | Out-Null
$counter = 0
if ($counter -lt 3) {
$counter ++
Write-Warning("Retrying Download in 3 seconds...")
Start-Sleep -Seconds 3
downloadFiles -urlList $urlList -location $location
}
Else {
$counter = 0
break
}
}
}
return $destFolder
}
#endregion
#region create array of URLs for download
function getSPPRurls() {
## Download SharePoint 2016 Prerequisite Installer files
$SPPRList = ("https://download.microsoft.com/download/4/B/1/4B1E9B0E-A4F3-4715-B417-31C82302A70A/ENU/x64/sqlncli.msi", # Microsoft SQL Server 2012 SP1 Native Client
"https://download.microsoft.com/download/B/9/D/B9D6E014-C949-4A1E-BA6B-2E0DEBA23E54/SyncSetup_en.x64.zip", # Microsoft Sync Framework Runtime v1.0 SP1 (x64)
"https://download.microsoft.com/download/A/6/7/A678AB47-496B-4907-B3D4-0A2D280A13C0/WindowsServerAppFabricSetup_x64.exe", # Windows Server AppFabric 1.1
"https://download.microsoft.com/download/0/1/D/01D06854-CA0C-46F1-ADBA-EBF86010DCC6/rtm/MicrosoftIdentityExtensions-64.msi", # Microsoft Identity Extensions (Windows Identity Foundation v1.1)
"https://download.microsoft.com/download/3/C/F/3CF781F5-7D29-4035-9265-C34FF2369FA2/setup_msipc_x64.exe", # Microsoft Information Protection and Control Client
"https://download.microsoft.com/download/F/1/0/F1093AF6-E797-4CA8-A9F6-FC50024B385C/AppFabric-KB3092423-x64-ENU.exe", # Cumulative Update 7 (KB3092423) for Microsoft AppFabric 1.1 for Windows Server
"https://download.microsoft.com/download/1/C/A/1CAA41C7-88B9-42D6-9E11-3C655656DAB1/WcfDataServices.exe", # Microsoft WCF Data Services 5.6
"https://download.microsoft.com/download/5/7/2/57249A3A-19D6-4901-ACCE-80924ABEB267/ENU/x64/msodbcsql.msi", # Microsoft ODBC Driver 11 for SQL Server
"https://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe", # Microsoft .NET Framework 4.6
"https://download.microsoft.com/download/3/C/F/3CF781F5-7D29-4035-9265-C34FF2369FA2/setup_msipc_x64.exe", # Microsoft Information Protection and Control Client
"https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe", # Visual C++ Redistributable Package for Visual Studio 2012
"https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe" # Visual C++ Redistributable for Visual Studio 2015
)
$destURL = downloadFiles -urlList $SPPRList -location "SPPR"
$bustedPOSH = !($destURL -is [string])
if ($bustedPOSH) {
Write-Host(" - Implementing PowerShell Bug Workaround...")
$destURL = $destURL.FullName
}
unzipSyncFiles -desturl $destURL
}
#endregion
#region unzip files
function unzipSyncFiles($destURL) {
$destURL = $destURL.Trim()
Add-Type -assembly "system.io.compression.filesystem"
$zipBackUpPath = $destURL + "\SyncSetup_en.x64.zip"
$zipDestination = $destURL + "\SyncSetup_en.x64"
$path = $zipDestination + "\Microsoft Sync Framework\Synchronization.msi"
$destination = $destURL + "\Synchronization.msi"
if (Test-Path $destination) {
Write-Host(" - Synchronization.msi is already extracted...")
}
if (!(Test-Path $destination)) {
Write-Host(" - Extracting SyncSetup_en.x64.zip to: $zipDestination")
if (Test-Path $zipDestination) {
Write-Host("Removing Unzipped Folder from: $zipDestination")
Remove-Item $zipDestination -Recurse -Force
}
[io.compression.zipfile]::ExtractToDirectory($zipBackUpPath, $zipDestination)
Copy-Item -Path $path -Destination $destination
Write-Host(" - Synchronization.msi unzipped and moved to prerequisiteinstallerfiles folder")
}
}
#endregion
#region Call Functions
validatePath -destFolder $destPath
getSPPRurls
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment