获取 MS Office 列表 [英] Get a List of MS Office
问题描述
好的,我正在尝试列出所有 Office 版本以及每个版本的数量.我们正在迁移到 Windows 10,我试图说服他将 Office 升级到 2016 年.我们的 Office 与 2010 年一样旧.我需要一份清单,列出我们拥有的每个版本的数量.即使我可以得到什么计算机有什么版本的列表.我尽量不要在每台计算机上单独运行审核,我们有 200 台计算机.
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
}
推荐答案
通常认为使用 Get-WmiObject
来检查 Win32_Product
类是不安全的,因为这可能会无意中触发修复安装在软件上.检查已安装程序的注册表更安全:
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'
}
}
这种工作方式是,对于两个注册表路径,我们希望从 $regPaths
获取基本路径下每个键的 DisplayName
值(这些主要用于是 GUID 命名的键,仅通过名称识别软件的价值不大).我们忽略错误,因为它们会使输出混乱,并且对于此操作,预计某些键可能没有 DisplayName
属性.我们不在乎这些.
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.
一旦我们为所有子项枚举了 DisplayName
,我们希望过滤掉名称中没有Office"的那些.请注意, -match
运算符不区分大小写,因此大小写在这里无关紧要.所以Where-Object
子句只返回一个DisplayName
,它在其中找到字符串office
.如果您知道您支持的每个 Office 版本的确切 DisplayName 字符串,您可以调整此正则表达式,因为这本质上会返回名称中包含 Office
的任何内容.
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.
这篇关于获取 MS Office 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!