29 December 2015

Microsoft Office Updater

Posted By: Mick Pletcher - 4:00 PM

Share

& Comment










One of the things that has annoyed me in the past is having to keep the Microsoft Office Updates folder up-to-date with the latest .MSP files. The reason I bother with keeping the Updates folder up-to-date is because it speeds up the process of building a golden image, which in my environment, Office is installed during that phase. To automate this process, I created an automatic deployment rule in SCCM that keeps the Microsoft Office software update group up-to-date with the latest Office updates. To bridge those updates with the Updates folder under the Office installation directory, I wrote the script below.

The script is setup to run as a scheduled task on the SCCM server once a week. It does not have to be setup to execute on a schedule, but it does make for one less thing to keep up with. The variables you will have to modify are $Country, $Source, and $Destination. You specify which country you need to include in the $Country variable on line 29. If you need multiple countries, you will have to modify this script. $Source will be the directory where the Deployment Package is written to on line 30. $Destination is the location of the Microsoft Office Updates folder on line 31. The files located on the SCCM server are all .CAB files, so this script automatically extracts the .MSP files from the .CAB files and places them in the Updates directory.


There is a newer version of this script located here.


1:  <#       
2:       .NOTES  
3:       ===========================================================================  
4:        Created with:     SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99  
5:        Created on:       12/29/2015 9:50 AM  
6:        Created by:       Mick Pletcher  
7:        Organization:         
8:        Filename:        OfficeUpdater.ps1  
9:       ===========================================================================  
10:       .DESCRIPTION  
11:            This script will keep the Updates folder populated with the latest Office  
12:            updates that SCCM has downloaded. It should be setup to execute as a   
13:            scheduled task on the SCCM server. I suggest executing it once a week.   
14:  #>  
15:    
16:  #Declare Variables  
17:  Set-Variable -Name Counter -Value 0 -Scope Local -Force  
18:  Set-Variable -Name Country -Scope Local -Force  
19:  Set-Variable -Name Destination -Scope Local -Force  
20:  Set-Variable -Name Executable -Scope Local -Force  
21:  Set-Variable -Name File -Scope Local -Force  
22:  Set-Variable -Name Files -Scope Local -Force  
23:  Set-Variable -Name Folder -Scope Local -Force  
24:  Set-Variable -Name Folders -Scope Local -Force  
25:  Set-Variable -Name Output -Scope Local -Force  
26:  Set-Variable -Name Parameters -Scope Local -Force  
27:  Set-Variable -Name Source -Scope Local -Force  
28:    
29:  $Country = "en-us"  
30:  $Source = "<SCCM Updates Source Directory>"  
31:  $Destination = "<Microsoft Office Updates folder>"  
32:  $Executable = $env:windir + "\System32\expand.exe"  
33:  If ($Country -notcontains "`*") {  
34:       $Country = "*" + $Country + "*"  
35:  }  
36:  $Folders = Get-ChildItem -Path $Source -Recurse | ?{ $_.PSIsContainer }  
37:  foreach ($Folder in $Folders) {  
38:       cls  
39:       $Counter++  
40:       $Output = "Processing " + $Counter + " of " + $Folders.Count  
41:       Write-Host $Output  
42:       $Files = Get-ChildItem -Path $Folder.Fullname -Recurse  
43:       foreach ($File in $Files) {  
44:            If (($File.Name -like $Country) -or ($File.Name -like "*none*")) {  
45:                 $Parameters = [char]34 + $File.FullName + [char]34 + [char]32 + [char]34 + $Destination + [char]34 + [char]32 + "-f:*"  
46:                 $ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Parameters -Wait -Passthru).ExitCode  
47:                 #Copy-Item -Path $File.FullName -Destination $Destination -Force  
48:            }  
49:       }  
50:  }  
51:    
52:  #Cleanup Variables  
53:  Remove-Variable -Name Counter -Scope Local -Force  
54:  Remove-Variable -Name Country -Scope Local -Force  
55:  Remove-Variable -Name Destination -Scope Local -Force  
56:  Remove-Variable -Name Executable -Scope Local -Force  
57:  Remove-Variable -Name File -Scope Local -Force  
58:  Remove-Variable -Name Files -Scope Local -Force  
59:  Remove-Variable -Name Folder -Scope Local -Force  
60:  Remove-Variable -Name Folders -Scope Local -Force  
61:  Remove-Variable -Name Output -Scope Local -Force  
62:  Remove-Variable -Name Parameters -Scope Local -Force  
63:  Remove-Variable -Name Source -Scope Local -Force  
64:    

About Mick Pletcher

My blog is here to help solve issues I have encountered and solved, publish scripts I have written, and educate others in understanding areas that are not well covered

0 comments:

Post a Comment

Copyright © 2013 Mick's IT Blogs™ is a registered trademark.