Powershell 有没有一种简单的方法可以确定哪些机器仍在运行Office 2010或2013?
我拼凑了一个powershell脚本,告诉我列表中的每台计算机上安装了哪些版本的office,但我只希望它输出缺少16.0 basekey的版本,以便知道哪些版本仍然需要它。如何调整我的代码来实现这一点Powershell 有没有一种简单的方法可以确定哪些机器仍在运行Office 2010或2013?,powershell,Powershell,我拼凑了一个powershell脚本,告诉我列表中的每台计算机上安装了哪些版本的office,但我只希望它输出缺少16.0 basekey的版本,以便知道哪些版本仍然需要它。如何调整我的代码来实现这一点 set-location -Path \\main\ Get-Content PClist.txt | ForEach-Object { Write-Output "$_" $reg=[Microsoft.Win32.RegistryKey]::OpenR
set-location -Path \\main\
Get-Content PClist.txt |
ForEach-Object {
Write-Output "$_"
$reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
$reg.OpenSubKey('software\Microsoft\Office').GetSubKeyNames() |% {$_}
}|
Out-file \\main\officeinstalls.txt
你需要做的是我们使用条件筛选出你不想要的(或者找到你想要的)。您可以做一些事情,比如将输出保存到数组或对象中,并对其进行迭代以仅获取所需内容 例子
你需要做的是我们使用条件筛选出你不想要的(或者找到你想要的)。您可以做一些事情,比如将输出保存到数组或对象中,并对其进行迭代以仅获取所需内容 例子 如果您只想让它输出那些缺少16.0键的内容来检查Office 2016的安装,您可以执行以下操作。如果机器是64位的,这也会检查32位安装
$result = Get-Content PClist.txt | ForEach-Object {
if (!(Test-Connection -ComputerName $_ -Count 1 -Quiet)) {
Write-Warning "Could not connect with computer '$_'"
# skip this computer and carry on with the next one
continue
}
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
try {
$key = $baseKey.OpenSubKey('SOFTWARE\Microsoft\Office\16.0')
if (!$key) {
# if this is a 64-bit machine, test for the 32-bit version of Office 2016
$key = $baseKey.OpenSubKey('SOFTWARE\Wow6432Node\Microsoft\Office\16.0')
}
# output the computer name if the '16.0' key was not found
if (!$key) { $_ }
}
catch {}
finally {
if ($key) { $key.Close() }
if ($baseKey) { $baseKey.Close() }
}
}
$result | Out-File -FilePath '\\main\NeedToInstallOffice2016.txt' -Force
如果您只想让它输出那些缺少16.0键的内容来检查Office 2016的安装,您可以执行以下操作。如果机器是64位的,这也会检查32位安装
$result = Get-Content PClist.txt | ForEach-Object {
if (!(Test-Connection -ComputerName $_ -Count 1 -Quiet)) {
Write-Warning "Could not connect with computer '$_'"
# skip this computer and carry on with the next one
continue
}
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
try {
$key = $baseKey.OpenSubKey('SOFTWARE\Microsoft\Office\16.0')
if (!$key) {
# if this is a 64-bit machine, test for the 32-bit version of Office 2016
$key = $baseKey.OpenSubKey('SOFTWARE\Wow6432Node\Microsoft\Office\16.0')
}
# output the computer name if the '16.0' key was not found
if (!$key) { $_ }
}
catch {}
finally {
if ($key) { $key.Close() }
if ($baseKey) { $baseKey.Close() }
}
}
$result | Out-File -FilePath '\\main\NeedToInstallOffice2016.txt' -Force
请更新您的问题,详细描述“16.0 basekey”指的是什么,以及您在使用当前代码时遇到的困难。我们尚未收到您的来信。。给出的答案解决了你的问题吗?如果是,请点击✓ 在左边。这将帮助其他有类似问题的人更容易找到它。请更新您的问题,详细描述“16.0 basekey”指的是什么,以及您在使用当前代码时遇到的困难。我们没有收到您的消息。。给出的答案解决了你的问题吗?如果是,请点击✓ 在左边。这将帮助其他有类似问题的人更容易地找到它。