Created
April 28, 2020 19:41
-
-
Save andikrueger/372006d55f79690ebaab4e20d8d072fe to your computer and use it in GitHub Desktop.
This gist shows a proof of concept for a AutoSpSourceBuilder DSC Resource
This file contains 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
Configuration AutoSpSourceBuilderDsc { | |
param ( | |
# SharePoint Patch Name - As Defined by AutoSPSourceBuilder | |
[Parameter()] | |
[System.String] | |
$SharePointPatchName, | |
# SharePoint Version (2013 or 2016) | |
[Parameter(Mandatory = $true)] | |
[Int] | |
$SharePointVersion | |
) | |
$binaryPath = "C:\Sources\SharePoint" | |
$patchFolder = "$($binaryPath)\$($SharePointVersion)\Patches\$($SharePointPatchName)" | |
$binaryPath = "$($binaryPath)\$($SharePointVersion)" | |
Script PatchSharePoint | |
{ | |
GetScript = { | |
return $null | |
} | |
TestScript = { | |
return Test-Path $using:patchFolder | |
} | |
SetScript = { | |
$autoSpSourceBuilderUrl = "https://raw.githubusercontent.com/brianlala/AutoSPSourceBuilder/master/AutoSPSourceBuilder.xml" | |
$autoSpSourceBuilderXml = New-Object System.Xml.XmlDocument | |
$autoSpSourceBuilderXml.Load($autoSpSourceBuilderUrl) | |
$productNode = $autoSpSourceBuilderXml.Products.Product | Where-Object -FilterScript { $_.Name -eq "SP$($using:SharePointVersion)" } | |
$cumulativeUpdates = $productNode.CumulativeUpdates.CumulativeUpdate | Where-Object -FilterScript { $_.Name -eq "$($using:SharePointPatchName)" } | |
New-Item -Type Directory -Path $using:patchFolder -Force | Out-Null | |
Import-Module -Name BitsTransfer | |
$cumulativeUpdates | ForEach-Object -Process { | |
$cu = $_ | |
$destinationFile = $($cu.Url).Split('/')[-1] | |
$job = Start-BitsTransfer -Asynchronous -Source $cu.Url -Destination "$($using:patchFolder)\$destinationFile" ` | |
-DisplayName "Downloading `'$destinationFile`' to $($using:patchFolder)\$destinationFile" -Priority Foreground ` | |
-Description "From $($cu.Url)" -RetryInterval 60 -RetryTimeout 3600 ` | |
-Verbose -ErrorVariable err | |
Write-Verbose " - Connecting..." | |
while ($job.JobState -eq "Connecting") | |
{ | |
Write-Verbose "." | |
Start-Sleep -Milliseconds 500 | |
} | |
If ($err) | |
{Throw | |
} | |
Write-Verbose " - Downloading $destinationFile..." | |
while ($job.JobState -ne "Transferred") | |
{ | |
$percentDone = "{0:N2}" -f $($job.BytesTransferred / $job.BytesTotal * 100) + "% - $($job.JobState)" | |
Write-Verbose $percentDone | |
Start-Sleep -Milliseconds 500 | |
$backspaceCount = (($percentDone).ToString()).Length | |
for ($count = 0; $count -le $backspaceCount; $count++) | |
{ | |
Write-Verbose "`b `b" | |
} | |
if ($job.JobState -like "*Error") | |
{ | |
Write-Verbose " - An error occurred downloading $destinationFile, retrying..." | |
Resume-BitsTransfer -BitsJob $job -Asynchronous | Out-Null | |
} | |
} | |
Write-Verbose " - Completing transfer..." | |
Complete-BitsTransfer -BitsJob $job | |
} | |
$items = Get-ChildItem -Path "$($using:patchFolder)" | |
$itemsToExtract = $items | Where-Object -FilterScript {$_.Extension -eq ".exe"} | |
$itemsToExtract | ForEach-Object -Process { | |
Start-Process -FilePath "$($using:patchFolder)\$($_.Name)" -ArgumentList "/extract:`"$($using:binaryPath)\ISO\Updates`" /passive" -Wait -NoNewWindow | |
} | |
$languagePackPatches = Get-ChildItem -Path "$(using:binaryPath)\ISO\Updates" -Filter "*de-de*" | |
$languagePackPatches | ForEach-Object -Process { | |
Copy-Item -Path $_.FullName -Destination "$(using:binaryPath)\LP\de\updates" -Force -Verbose | |
} | |
} | |
DependsOn = $dependsOn | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment