O365 Powershell Module Install Script

I hope MS will consolidate the O365 Powershell modules in the future.  As it stands today your best bet is to find this page, follow the links to download four Powershell modules, and establish connections to the various MS online providers.  Or run the following if you have a minute. Certain assumptions are made below, like Skype for Business module being the only .exe, but this should get you started.

Please note Windows 10 isn’t listed as a supported OS but all modules seem to be fine. A reboot was required on my test Windows 10 client to get the Skype for Business module to work properly.

 

# Copyright (c) 2017 infiniteloop.io
# http://infiniteloop.io
# Version 1.0 - February 15, 2017
# 
# Redistribution and use in source and binary forms, with or without modification, are permitted 
# provided that the following conditions are met:
# 1) Redistributions of source code must retain the above copyright notice, this list of conditions 
#     and the following disclaimer.
# 2)  Redistributions in binary form must reproduce the above copyright notice, this list of conditions 
#     and the following disclaimer in the documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# Can be run as .ps1 or directly from ISE
# Install files will download to directory where .ps1 is called or $env:TEMP
if($host.name -match 'console') {$scriptDir = Split-Path $MyInvocation.MyCommand.Definition -Parent} else {$scriptDir = $env:TEMP}

if($host.Version.Major -lt 3){Read-Host "Powershell v3 or higher is required to run this script`nCurrent host version:  $($host.version.tostring())`n";break}

$URLarr = @(
  'https://download.microsoft.com/download/5/0/1/5017D39B-8E29-48C8-91A8-8D0E4968E6D4/en/msoidcli_64.msi'
  'https://bposast.vo.msecnd.net/MSOPMW/Current/amd64/AdministrationConfig-en.msi'
  'https://download.microsoft.com/download/0/2/E/02E7E5BA-2190-44A8-B407-BC73CA0D6B87/sharepointonlinemanagementshell_6112-1200_x64_en-us.msi'
  'https://download.microsoft.com/download/2/0/5/2050B39B-4DA5-48E0-B768-583533B42C3B/SkypeOnlinePowershell.exe'
)

$downloadCount = 0
$URLarr | % {
  try 
  {
    $fileName = $_.Split('/')[-1]
    Write-Host "Begin download for $filename" -f Green
    Invoke-WebRequest -Uri $_ -OutFile "$scriptDir\$fileName" -ea stop
    $downloadcount++
  } 
  catch 
  {
    write-host "${filename}: $($_.exception.message)" -f Red
  }
}

Write-Host "`n`n"

if($downloadCount -eq $URLarr.count)
{
  write-host 'All files have been downloaded, begin installation...' -f Green

  $MSIArr = @()
  $MSIArr += gci $scriptDir -Filter "*.msi" | sort LastWriteTime #maintain prereq order so MS Online Services Sign-in Assistant runs first
  $MSIArr | % {"$($_.name) Install Exit Code: " + (Start-Process 'msiexec.exe' -ArgumentList "/qb /i `"$($_.FullName)`" /l*v `"$($env:TEMP)\$($_.name).log`"" -Wait -PassThru).exitcode}
  
  $EXEArr = @()
  $EXEArr += gci $scriptDir -Filter "*.exe" | sort LastWriteTime
  $EXEArr | % {"$($_.name) Install Exit Code: " + (Start-Process $_.fullname -ArgumentList "/passive /norestart /log `"$($env:TEMP)\$($_.name).log`"" -Wait -PassThru).exitcode}
}
else
{
  Write-Host "Download file count doesn't match total number of URLs, check paths and re-run"
}