-
Notifications
You must be signed in to change notification settings - Fork 4
/
Get-FBCMOfficeUpdatesFromCab.ps1
77 lines (68 loc) · 2.71 KB
/
Get-FBCMOfficeUpdatesFromCab.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Author - Fred Bainbridge
# Originally Published 5/31/2016
#
# Usage Examples
#
# Use the defaut parameters in the script (update as needed)
# Get-Office2016MSPFromCab -UpdateDP $true -siteCode "LAB" -siteserver "cm01.cm.lab"
#
# Use explicit parameters, do not update the Distribution Points
# Get-Office2016MSPFromCab -SoftwareUpdatesFolder "\\cm01\SoftwareUpdates\Office2016x86Updates" -baseDestination "c:\fso1" -OfficeUpdatesFolder "\\cm01\Source\Microsoft Office 2016 x86\updates"
#special thanks to https://technet.microsoft.com/en-us/magazine/2009.04.heyscriptingguy.aspx
[CmdletBinding()]
param (
$SoftwareUpdatesFolder = "\\cm01\Software Update Management\Office 2016 Updates",
$baseDestination = "C:\fso1",
$OfficeUpdatesFolder = "\\cm01\Source\Microsoft Office 2016 x86\updates",
[bool]$UpdateDP = $false,
$siteCode = "LAB",
$siteserver = "cm01.cm.lab",
$appname = "Microsoft Office 2016 x86"
)
Function ConvertFrom-Cab
{
[CmdletBinding()]
Param(
$cab = "C:\fso\acab.cab",
$destination
)
$comObject = "Shell.Application"
Write-Verbose "Creating $comObject"
$shell = New-Object -Comobject $comObject
if(!$?) { $(Throw "unable to create $comObject object")}
Write-Verbose "Creating source cab object for $cab"
$sourceCab = $shell.Namespace("$cab").items()
Write-Verbose "Creating destination folder object for $destination"
if(-not (Test-Path $destination))
{
new-item $destination -ItemType Directory
}
$DestinationFolder = $shell.Namespace($destination)
Write-Verbose "Expanding $cab to $destination"
$DestinationFolder.CopyHere($sourceCab)
}
if(-not (test-path $baseDestination))
{
new-item $baseDestination -ItemType Directory
}
#get all the cab files and copy them locally
Write-Verbose $SoftwareUpdatesFolder
Get-ChildItem -Path $SoftwareUpdatesFolder -Filter *.cab -Recurse | ForEach-Object {
$GUID = (new-guid).Guid
$destination = "$baseDestination\$GUID"
Write-Verbose $destination
ConvertFrom-Cab -cab $PSItem.FullName -destination $destination -Verbose
}
#rename and prepare the files for copy
Get-ChildItem -path $baseDestination -Filter *.msp -Recurse | ForEach-Object {
Rename-Item -Path $PSItem.FullName -NewName ($PSItem.BaseName + (New-Guid).GUID + ".msp")
}
Get-ChildItem -Path $baseDestination -Filter *.msp -Recurse | Move-Item -Destination $baseDestination
#move the cabs to the Office Updates folder
Get-ChildItem -Path $baseDestination -Filter *.msp | move-item -Destination $OffiCeUpdatesFolder -Verbose
#cleanup
Get-ChildItem -Path $baseDestination | Remove-Item -Recurse -Force -Verbose
#Update the content
if($UpdateDP){
(Get-Wmiobject -Namespace "root\SMS\Site_$sitecode" -Class SMS_ContentPackage -filter "Name='$appName'").Commit()
}