Wednesday, July 1, 2015

Automating Office 365 Updates in SCCM with Powershell!

Hello everyone!  It has been way too long since the last time I posted here, something I hope to rectify.  Today I would like to talk about Office 365, specifically the Office Click-to-Run package and how you can automate updates in a more controlled manor using PowerShell and Group Policy!

For those who do not know, there are two ways to install Office on your system when you are licensed through Office 365.  There is the standard MSI version that you know and love (if your subscription level allows), as well as the new "Click-to-Run" method, or C2R for short.  C2R is really neat since it is basically a self-contained App-V package that doesn't require the full App-V experience installed on your system.  The biggest benefit (or frustration) of C2R is that the update mechanism changes which allows updates to come in faster ... but it does not use traditional methods such as WSUS or Windows Update.

A bit of back story, at my company we recently deployed Office 365 out to everyone and made the decision to let updates stream automatically from the web.  According to documentation systems should only download the delta difference between the current version and the previous version, so the update traffic shouldn't be too bad.  In hind-sight, this was a terrible idea for a couple of reasons.  The first reason is that we have just shy of 1000 systems/O365 licenses so the sheer number of systems weren't taken into account.  The second is that for some reason, all of our systems decided to download the ENTIRE OFFICE INSTALL instead of just the delta.  To make matters worse, all of this download traffic started on a day that we launched a user outreach program which focused on training and implementation of the Modern Workplace (i'll post about that another time).

So, on to the fun bits.  How we solved our updates issues:

Basically, I wrote a PowerShell script that does the following:

  1. Deletes the current Office 365 Install Source from SCCM Server and from a Shared Network Location
  2. Downloads the latest version of Office 365 and copies the content to a Shared Network Location
  3. Connects to SCCM Database
  4. Updates the Application Version to the version being deployed
  5. Updates Distribution Points with the latest Office package
For the Shared Network Location we are using a path that is replicated to all of our offices so that the actual update happens locally and not streaming over our WAN.

Here is the PowerShell Script with comments:

#  Here you are only removing the "Office" folder inside your source package.  Don't remove the parent folder which has Setup.exe and your XML files, you can reuse these.  For your Shared Network Location you can delete everything.  This assumes that you are not specifying a version in your XML file

Remove-Item -Path "\\SCCMServer\PathTo\Office365\Office" -Recurse
Remove-Item -Path "\\SharedLocation\Path\Office365" -Recurse

# Downloads New Office 365 Content based on your XML and waits until the download is complete

Start-Process setup.exe -WorkingDirectory "\\SCCMServer\PathTo\Office365" -Verb open -args "/download configuration.xml" -Wait

# Grabs the name of the folder that contains the actual office content and stores it as a variable

$a = Get-ChildItem -Path "\\SCCMServer\PathTo\Office365\Office\Data" -Directory

# Copies Office data to your shared network location

Copy-Item -Path "\\SCCMServer\PathTo\Office365\Office" -Destination "\\SharedLocation\Path\Office365" -Recurse

# This line is needed if you are not running your script from your ConfigMgr Server.  The path here is the installation directory of SCCM on your server.  You can also use the installation path for the SCCM console if you wish.  This loads the SCCM Powershell modules so that the rest of the script will work

import-module "\\SCCMServer\Installdir\AdminConsole\bin\ConfigurationManager.psd1"

# Connects to your SCCM Database, where PRI = your site code

Set-Location PRI:

#This updates the Application version number.

Set-CMApplication -Name "Your Application Name" -SoftwareVersion $a

#This Updates your distribution points with the latest version of the Office 365 package

Update-CMDistributionPoint -ApplicationName "Your Application Name" -DeploymentTypeName "Your Deployment Name"

There you have it!  I'm sure many of you are asking "Why am I deleting everything before downloading?" and the answer is simple:

When you download the Office 365 deployment it creates a folder under Office\Data with the new deployment version, and will not remove the old one.  Deleting the old version ensures that your Office deployment package doesn't contain any stale information.  Also, the script runs on the assumption that there is only one folder inside Office\Data, and uses that to update the SoftwareVersion later on.

Here is the script without all the comments:

Remove-Item -Path "\\SCCMServer\PathTo\Office365\Office" -Recurse
Remove-Item -Path "\\SharedLocation\Path\Office365" -Recurse

Start-Process setup.exe -WorkingDirectory "\\SCCMServer\PathTo\Office365" -Verb open -args "/download configuration.xml" -Wait

$a = Get-ChildItem -Path "\\SCCMServer\PathTo\Office365\Office\Data" -Directory

Copy-Item -Path "\\SCCMServer\PathTo\Office365\Office" -Destination "\\SharedLocation\Path\Office365" -Recurse

import-module "\\SCCMServer\Installdir\AdminConsole\bin\ConfigurationManager.psd1"
Set-Location PRI:

Set-CMApplication -Name "Your Application Name" -SoftwareVersion $a
Update-CMDistributionPoint -ApplicationName "Your Application Name" -DeploymentTypeName "Your Deployment Name"

No comments: