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