-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-OfficeVer.ps1
More file actions
25 lines (23 loc) · 814 Bytes
/
Copy pathGet-OfficeVer.ps1
File metadata and controls
25 lines (23 loc) · 814 Bytes
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
#Function to read office version
function Get-OfficeVer ($computer = $env:COMPUTERNAME) {
$version = $null
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
try {
$reg.OpenSubKey('SOFTWARE\Microsoft\Office').GetSubKeyNames() | ForEach-Object {
if ($_ -match '(\d+\.\d+)') {
$numericVersion = [int][math]::Truncate([decimal]$_)
if ($numericVersion -gt $version) {
$version = $_
}
}
}
} catch {
Write-Error "Failed to query the registry: $($_.Exception.Message)"
}
if ($version -ne $null) {
return $version
} else {
Write-Output "No Office version found."
return $null
}
}