简体   繁体   中英

Get a List of MS Office

Ok, I am trying to get a list off all Office versions and how many of each. We are migrating to Windows 10 and I am trying to talk him into upgrading office to 2016. We have Office as old as 2010. I need a list of how many of each version we have. Even if i can get a list of what computer has what version. I am trying not to run an audit on every computer individually, we have 200 computers.

I have tried several different approaches.

Get-ADComputer -Filter * -Property * | Select-Object Name |
 Export-CSV ADcomputerslist.csv -NoTypeInformation -Encoding UTF8

This doesnt actually save to a file

foreach ($computer in (Get-Content "c:\computers.txt")){
  Write-Verbose "Working on $computer..." -Verbose
  Invoke-Command -ComputerName "$Computer" -ScriptBlock {
    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\O365ProPlusRetail* |
    Select-Object DisplayName, DisplayVersion, Publisher
  } | export-csv C:\results.csv -Append -NoTypeInformation
}

It's generally considered unsafe to use Get-WmiObject to check the Win32_Product class because this can unintentionally trigger repair installs on software. It's safer to check the registry for installed programs:

# We need to check for both 64-bit and 32-bit software
$regPaths = "HKLM:\SOFTWARE\Wow6432node\Microsoft\Windows\CurrentVersion\Uninstall",
  "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

# Get the name of all installed software registered in the registry with Office in the name
# (you can search for exact strings if you know them for specific versions)
$regPaths | Foreach-Object {
  ( Get-ItemProperty "${_}\*" DisplayName -EA SilentlyContinue ).DisplayName | Where-Object {
    $_ -match 'office'
  }
}

The way this works is that for both registry paths, we want to get the DisplayName value every key underneath the base path from $regPaths (these are mostly going to be GUID-named keys, not much value for just identifying the software by name). We ignore errors since they will clutter the output and for this operation it's expected that some keys may not have a DisplayName property. We don't care about those.

Once we have the DisplayName enumerated for all of the subkeys, we want to filter out the ones that do not have 'Office' in the name. Note that the -match operator is case-insensitive, so casing doesn't matter here. So the Where-Object clause only returns a DisplayName of it finds the string office in it. You can tweak this regular expression if you know exact DisplayName strings for each version of Office you support, as inherently this will return anything with Office in the name.

As an alternative you could read the (default) registry value for one of the Office applications like Word and translate the version number:

foreach ($computer in (Get-Content "c:\computers.txt")){
  Write-Verbose "Working on computer '$computer'..." -Verbose

  Invoke-Command -ComputerName $computer -ScriptBlock {
    (Get-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\Word.Application\CurVer").'(default)' | ForEach-Object {
        [PsCustomObject] @{
            'Computer' = $computer
            'OfficeVersion' = 
                    switch ([int]($_ -split '\.')[-1]) {
                            16 {'MS Office 2016 OR MS Office 2019 or MS Office 365'; break}
                            15 {'MS Office 2013'; break}
                            14 {'MS Office 2010'; break}
                            12 {'MS Office 2007'; break}
                            11 {'MS Office 2003'}
                        }
        }
    }
  } 
}

Output (something like):

 Computer OfficeVersion -------- ------------- PC_01 MS Office 2013 PC_02 MS Office 2010 

Unfortunately, Office 2019 and Office 2016 are no longer differentiated by a different version number in this registry value..

I would do it like this :-

First start the WinRM serviice

Get-Service -Name WinRM  -ComputerName machinename | Start-service

Then once we have that we can query WinRM for all the installed applications.

Get-CimInstance -ComputerName machinename -ClassName win32_product | Select-Object PSComputerName, Name, PackageName, InstallDate 

Then its good practice disable WinRM when you have finished

Get-Service -Name WinRM  -ComputerName df-ps-sitpc17 | Stop-service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM