Link to home
Start Free TrialLog in
Avatar of smart Z
smart Z

asked on

script to find if office version

Hello experts,

I want to pull a report in the form of a csv from users computers that will show what version of MS Office is installed.

I am not sure what to use and I will appreciate if I can have simple script.

Thank u,
Avatar of Alexios Valonasis
Alexios Valonasis
Flag of Greece image

Avatar of smart Z
smart Z

ASKER

it did not work actually. Is there a manual way to do this ?
Try to query the system registry entries using command line.

To get the windows version using System registry , use the following command:

reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "ProductName"
This will give an output which can be parsed to get the current windows version/name.

To get the current office version , use:

reg query "HKEY_CLASSES_ROOT\Word.Application\CurVer"
The output of this command gives the office version in number format such as 14, 15, etc.

Parse the output to get the version number and match against the list of existing Microsoft office versions to get the name of the version installed:

Office 97   -  7.0
Office 98   -  8.0
Office 2000 -  9.0
Office XP   - 10.0
Office 2003 - 11.0
Office 2007 - 12.0
Office 2010 - 14.0
Office 2013 - 15.0
Avatar of smart Z

ASKER

My tech will need to query the registry remotely . How will he connect? By not interrupting the user.
Use the information provided in this Microsoft link
https://technet.microsoft.com/en-us/library/cc742028.aspx
add Office 2016      Word.Application.16
the remote registry service must be enabled to query remote machines.
<#
.Synopsis
   Get-OfficeVersion 
.DESCRIPTION
   Gets the Office version from a list of computernames and returns a CSV of the Computername and Office Version (if available)
.EXAMPLE
 get-officeversion c:\test\servers.txt c:\test\officeversions.csv
.EXAMPLE
 get-officeversion -infile c:\test\servers.txt -outfile c:\test\officeversions.csv
.NOTES
   General notes
#>
function Get-OfficeVersion
{
param(
    [Parameter(Mandatory=$true)]
    [string] $Infile,
    [Parameter(Mandatory=$true)]
    [string] $outfile
    )
#$outfile = 'C:\temp\office.csv'
#$infile = 'c:\temp\servers.txt'
Begin
    {
    }
 Process
    {
    $office = @()
    $computers = Get-Content $infile
    $i=0
    $count = $computers.count
    foreach($computer in $computers)
     {
     $i++
     Write-Progress -Activity "Querying Computers" -Status "Computer: $i of $count " `
      -PercentComplete ($i/$count*100)
        $info = @{}
        $version = 0
        try{
          $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer) 
          $reg.OpenSubKey('software\Microsoft\Office').GetSubKeyNames() |% {
            if ($_ -match '(\d+)\.') {
              if ([int]$matches[1] -gt $version) {
                $version = $matches[1]
              }
            }    
          }
          if ($version) {
            Write-Debug("$computer : found $version")
            switch($version) {
                "7" {$officename = 'Office 97' }
                "8" {$officename = 'Office 98' }
                "9" {$officename = 'Office 2000' }
                "10" {$officename = 'Office XP' }
                "11" {$officename = 'Office 97' }
                "12" {$officename = 'Office 2003' }
                "13" {$officename = 'Office 2007' }
                "14" {$officename = 'Office 2010' }
                "15" {$officename = 'Office 2013' }
                "16" {$officename = 'Office 2016' }
                default {$officename = 'Unknown Version'}
            }
    
          }
          }
          catch{
              $officename = 'Not Installed/Not Available'
          }
    $info.Computer = $computer
    $info.Name= $officename
    $info.version =  $version

    $object = new-object -TypeName PSObject -Property $info
    $office += $object
    }
    $office | select computer,version,name | Export-Csv -NoTypeInformation -Path $outfile
    }
}
  write-output ("Done")

Open in new window

get-officeversion.ps1..txt
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of smart Z

ASKER

Hello David,

The list of computers I have should be in text file or CSV? Do I put file in C:\Temp before I run the powershell script.

Thanks