|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Check or set the Office Bitness/Platform registry values. |
| 4 | +
|
| 5 | +.PARAMETER Architecture |
| 6 | +The architecture to set. Valid values are 'x86' or 'x64'. Default is 'x86'. |
| 7 | +
|
| 8 | +.PARAMETER Check |
| 9 | +Check the current Office Bitness/Platform registry values. This is the default action. |
| 10 | +
|
| 11 | +.PARAMETER Set |
| 12 | +Set the Office Bitness/Platform registry values to the specified Architecture. |
| 13 | +#> |
| 14 | + |
| 15 | +[CmdletBinding()] |
| 16 | +param ( |
| 17 | + [ValidateSet('x86','x64')] |
| 18 | + [string] $Architecture = 'x86', |
| 19 | + [switch] $Check, |
| 20 | + [switch] $Set |
| 21 | +) |
| 22 | + |
| 23 | +Begin |
| 24 | +{ |
| 25 | + $UninstallPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" |
| 26 | + |
| 27 | + $RegistryPaths = @( |
| 28 | + @{ Path = 'HKLM:\Software\Microsoft\Office\16.0\Outlook'; Key = 'Bitness' }, |
| 29 | + @{ Path = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Outlook'; Key = 'Bitness' }, |
| 30 | + @{ Path = 'HKLM:\Software\Microsoft\Office\ClickToRun\Configuration'; Key = 'Platform' } |
| 31 | + ) |
| 32 | + |
| 33 | + function CheckBitness |
| 34 | + { |
| 35 | + $status = (CheckOffice) ? 'is' : 'is not' |
| 36 | + Write-Host |
| 37 | + Write-Host "... Office $status installed" -Fore Yellow |
| 38 | + |
| 39 | + Write-Host |
| 40 | + foreach ($item in $registryPaths) |
| 41 | + { |
| 42 | + $path = $item.Path |
| 43 | + $key = $item.Key |
| 44 | + |
| 45 | + try |
| 46 | + { |
| 47 | + $props = Get-ItemProperty -Path $path -ErrorAction Stop |
| 48 | + Write-Host "... $path`\$key: $($props.$key)" |
| 49 | + } |
| 50 | + catch |
| 51 | + { |
| 52 | + Write-Host "... $path not found or inaccessible" -Fore DarkGray |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + function CheckOffice |
| 58 | + { |
| 59 | + $count = (Get-ItemProperty $UninstallPath | where { |
| 60 | + $_.DisplayName -like "*Office*" } | Measure).Count |
| 61 | + |
| 62 | + return $count -gt 0 |
| 63 | + } |
| 64 | + |
| 65 | + function SetBitness |
| 66 | + { |
| 67 | + param($Bitness) |
| 68 | + |
| 69 | + Write-Host |
| 70 | + foreach ($item in $registryPaths) |
| 71 | + { |
| 72 | + $path = $item.Path |
| 73 | + $key = $item.Key |
| 74 | + |
| 75 | + try |
| 76 | + { |
| 77 | + Write-Host "... setting $path\$key to '$Bitness'" |
| 78 | + |
| 79 | + # create key if it doesn't exist |
| 80 | + if (-not (Test-Path $path)) |
| 81 | + { |
| 82 | + New-Item -Path $path -Force | Out-Null |
| 83 | + } |
| 84 | + |
| 85 | + Set-ItemProperty -Path $path -Name $key -Value $Bitness -Force |
| 86 | + } |
| 87 | + catch |
| 88 | + { |
| 89 | + Write-Host "*** failed to write to $path`: $_" -Fore Red |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + #> |
| 94 | +} |
| 95 | +Process |
| 96 | +{ |
| 97 | + if ($Check -or !$Set) |
| 98 | + { |
| 99 | + CheckBitness |
| 100 | + return |
| 101 | + } |
| 102 | + |
| 103 | + if ($Set) |
| 104 | + { |
| 105 | + if (CheckOffice) |
| 106 | + { |
| 107 | + Write-Host "`nOffice is installed! This may overwrite your Office configuration." -Fore Yellow |
| 108 | + $choice = Read-Host "`n... Are you sure you want to write Bitness/Platform values? (y/n)" |
| 109 | + if ($choice -ne 'y') { return } |
| 110 | + } |
| 111 | + |
| 112 | + SetBitness $Architecture |
| 113 | + } |
| 114 | +} |
0 commit comments