Skip to content

Instantly share code, notes, and snippets.

@klkvsk
Created November 4, 2023 21:38
Show Gist options
  • Save klkvsk/f91484525a5bfd34b5fe2dda841b5694 to your computer and use it in GitHub Desktop.
Save klkvsk/f91484525a5bfd34b5fe2dda841b5694 to your computer and use it in GitHub Desktop.
Single script to install/update MS Office. Also unblocks blocked regions ("Command not supported" error)
## !!! Run as Administrator
## !!! VPN is required for setup from blocked regions
## - Also, if you are still blocked, try `Set-WinHomeLocation -GeoId 244` (244=USA)
## - Know that setup.exe writes detailed logs to %TEMP%
# BetaChannel -> CurrentPreview -> Current -> MonthlyEnterprise -> SemiAnnualPreview -> SemiAnnual
$CHANNEL = "CurrentPreview"
# modify this to your needs
# https://github.com/MicrosoftDocs/OfficeDocs-DeployOffice/blob/public/DeployOffice/office-deployment-tool-configuration-options.md
[string]$odtConfig=@"
<Configuration ID="f2e3ab44-3261-4dc3-b1cf-0929ab58836e">
<Add OfficeClientEdition="64" Channel="$CHANNEL">
<Product ID="O365HomePremRetail">
<Language ID="en-us" />
<ExcludeApp ID="Access" />
<ExcludeApp ID="Groove" />
<ExcludeApp ID="Lync" />
<ExcludeApp ID="OneDrive" />
<ExcludeApp ID="PowerPoint" />
<ExcludeApp ID="Publisher" />
<ExcludeApp ID="Teams" />
<ExcludeApp ID="Bing" />
<ExcludeApp ID="OneNote" />
</Product>
<Product ID="ProofingTools">
<Language ID="ru-ru" />
</Product>
</Add>
<Updates Enabled="TRUE" Channel="$CHANNEL"/>
<Display Level="Full" AcceptEULA="TRUE" />
<RemoveMSI />
</Configuration>
"@
Write-Output '---'
Write-Output $odtConfig
Write-Output '---'
Write-Host "Apply this deployment configuration?" -InformationAction Inquire
$odtConfigPath = $PSScriptRoot + "\odt-config.xml"
Set-Content -Path $odtConfigPath -Value $odtConfig
if ((Test-Path "$PSScriptRoot\setup.exe") -eq $false) {
## winget is broken, see https://github.com/microsoft/winget-pkgs/issues/96841
# winget Microsoft.OfficeDeploymentTool
echo "Downloading MS Office Deployment Tool"
$downloadPage = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=49117";
$exeUrl = ($downloadPage.Links | Where href -like "*.exe").href;
Start-BitsTransfer -Source $exeUrl -Destination $PSScriptRoot
$exeFile = Split-Path $exeUrl -Leaf
echo "Extracting"
Start-Process $PSScriptRoot\$exeFile -ArgumentList ("/extract:$PSScriptRoot", "/passive", "/quiet") -Wait -NoNewWindow
}
# current region is stored here:
$cleanupRegKeys = (
'HKCU:\Software\Microsoft\Office\16.0\Common\Experiment',
'HKCU:\Software\Microsoft\Office\16.0\Common\ExperimentConfigs',
'HKCU:\Software\Microsoft\Office\16.0\Common\ExperimentEcs'
)
foreach ($regKey in $cleanupRegKeys) {
if (Test-Path $regKey) {
echo "Removing registry key $regKey"
Remove-Item -Path $regKey -Force -Recurse
}
}
echo "Running setup"
Start-Process $PSScriptRoot\setup.exe -ArgumentList ("/configure", $odtConfigPath) -Wait -NoNewWindow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment