[PowerShell]–Checking the version of Office installed
2024-10-21 06:11:00
– Create and initialize the object
$objExcel = New-Object -ComObject Excel.Application
– Query the version of the Office installed
$objExcel.version
– Query the build of the Office installed
$objExcel.build
Get-OfficeVersion function原文地址:http://www.amandhally.net/2013/07/03/powershell-script-get-the-file-and-product-version-of-ms-office-applications/
function Get-OfficeVersion{
<#
.SYNOPSIS
Get's the Version info of Word, Excel, Outlook, and PowerPoint.
.DESCRIPTION
Out-of-the box, a Windows system automatically shares the root of every hard drive on the machine as $ (so you get C$, D$, A$, etc). These shares need to be enabled. The shares are ACL’ed so that only members of the local administrative group can access them.
.EXAMPLE
.NOTES
.LINK
http://www.amandhally.net/2013/07/03/powershell-script-get-the-file-and-product-version-of-ms-office-applications/
http://blogs.msdn.com/b/larryosterman/archive/2005/05/26/422188.aspx
#>
[cmdletbinding()]
param(
#The computers to get
[Parameter(ValueFromPipeline=$true)]
[string[]]$ComputerName=$env:COMPUTERNAME
)
begin{}
process{
foreach($Computer in $ComputerName){
#$wordPath = “\\$Computer\C`$\Program Files*\Microsoft Office\Office*\WINWORD.EXE”
#$excelPath = “\\$Computer\C`$\Program Files*\Microsoft Office\Office*\EXCEL.EXE”
#$powepointPath = “\\$Computer\C`$\Program Files*\Microsoft Office\Office*\POWERPNT.EXE”
$outlookPath = “\\$Computer\C`$\Program Files*\Microsoft Office\Office*\OUTLOOK.EXE”
try{
#$wordProperty = Get-ItemProperty -Path $wordPath -ErrorAction Stop
#$excelProperty = Get-ItemProperty -Path $excelPath -ErrorAction Stop
$outLookProperty = Get-ItemProperty -Path $outlookPath -ErrorAction Stop
#$powerPointProperty = Get-ItemProperty -Path $powepointPath -ErrorAction Stop
Write-Output ([PSCustomObject]@{ComputerName=$Computer;Office=$outLookProperty.VersionInfo.ProductVersion})
<#Write-Output ([PSCustomObject]@{ComputerName=$Computer;Office=@(
[PSCustomObject]@{Product=’Word’;ProductVersion=$wordProperty.VersionInfo.ProductVersion;FileVersion=$wordProperty.VersionInfo.FileVersion},
[PSCustomObject]@{Product=’Excel’;ProductVersion=$excelProperty.VersionInfo.ProductVersion;FileVersion=$excelProperty.VersionInfo.FileVersion},
[PSCustomObject]@{Product=’Outlook’;ProductVersion=$outLookProperty.VersionInfo.ProductVersion;FileVersion=$outLookProperty.VersionInfo.FileVersion},
[PSCustomObject]@{Product=’PowerPoint’;ProductVersion=$powerPointProperty.VersionInfo.ProductVersion;FileVersion=$powerPointProperty.VersionInfo.FileVersion}
)})#>
}
catch{
Write-Error $Error[0]
}
}
}
end{}
}
<#$servers=get-content D:\clist.txt
$OFF=Get-OfficeVersion -ComputerName $servers
$OFF | select computername,office | export-csv d:\ctest1-100.csv -Encoding UTF8 -NoTypeInformation
#> $servers=get-content D:\serverlist1223.txt
$export=@()
foreach($server in $servers)
{
$Pingy = Get-WmiObject Win32_PingStatus -f "Address='$server'"
if($Pingy.StatusCode -eq 0)
{
$errorcount=$error.count
$OFF=(Get-OfficeVersion -ComputerName $server).office
if($errorcount -eq $error.Count)
{
if($OFF)
{
$info=New-Object psobject
$info |Add-Member -MemberType NoteProperty -Name ComputerName -Value $server
$info |Add-Member -MemberType NoteProperty -Name office -Value $OFF
$export+=$info
echo "$server is $OFF"
}
else{
$info=New-Object psobject
$info |Add-Member -MemberType NoteProperty -Name ComputerName -Value $server
$info |Add-Member -MemberType NoteProperty -Name office -Value "NO OFFICE"
$export+=$info
echo "$server is no office"
}
}
else{
$info=New-Object psobject
$info |Add-Member -MemberType NoteProperty -Name ComputerName -Value $server
$info |Add-Member -MemberType NoteProperty -Name office -Value "error"
$export+=$info
echo "$server is error"
}
}
else{
$info=New-Object psobject
$info |Add-Member -MemberType NoteProperty -Name ComputerName -Value $server
$info |Add-Member -MemberType NoteProperty -Name office -Value "notavailable"
$export+=$info
echo "$server is notavailable "
}
}
$export |Export-Csv D:\officeserver.csv -Encoding UTF8 -NoTypeInformation
Get-MSOfficeProductKey function
function Get-MSOfficeProductKey {
param(
[string[]]$computerName = "."
)
$product = @()
$hklm = 2147483650
$path = "SOFTWARE\Microsoft\Office"
foreach ($computer in $computerName) {
$wmi = [WMIClass]"\\$computer\root\default:stdRegProv"
$subkeys1 = $wmi.EnumKey($hklm,$path)
foreach ($subkey1 in $subkeys1.snames) {
$subkeys2 = $wmi.EnumKey($hklm,"$path\$subkey1")
foreach ($subkey2 in $subkeys2.snames) {
$subkeys3 = $wmi.EnumKey($hklm,"$path\$subkey1\$subkey2")
foreach ($subkey3 in $subkeys3.snames) {
$subkeys4 = $wmi.EnumValues($hklm,"$path\$subkey1\$subkey2\$subkey3")
foreach ($subkey4 in $subkeys4.snames) {
if ($subkey4 -eq "digitalproductid") {
$temp = "" | select ComputerName,ProductName,ProductKey
$temp.ComputerName = $computer
$productName = $wmi.GetStringValue($hklm,"$path\$subkey1\$subkey2\$subkey3","productname")
$temp.ProductName = $productName.sValue
$data = $wmi.GetBinaryValue($hklm,"$path\$subkey1\$subkey2\$subkey3","digitalproductid")
$valueData = ($data.uValue)[52..66]
# decrypt base24 encoded binary data
$productKey = ""
$chars = "BCDFGHJKMPQRTVWXY2346789"
for ($i = 24; $i -ge 0; $i--) {
$r = 0
for ($j = 14; $j -ge 0; $j--) {
$r = ($r * 256) -bxor $valueData[$j]
$valueData[$j] = [math]::Truncate($r / 24)
$r = $r % 24
}
$productKey = $chars[$r] + $productKey
if (($i % 5) -eq 0 -and $i -ne 0) {
$productKey = "-" + $productKey
}
}
$temp.ProductKey = $productKey
$product += $temp
}
}
}
}
}
}
$product
}
# Example:
# Get-MSOfficeProductKey Serv01,Serv02 | Format-Table * -auto# Get-MSOfficeProductKey -computerName (Get-Content servers.txt)
来自
最新文章
- Codeforces Round #361 (Div. 2) A
- Http相关知识
- RMAN-06023: no backup or copy of datafile 1 found to restore
- UML统一建模编程
- 使用explain查看mysql查询执行计划
- ArcEngine中License权限等级更改的问题
- 一个自定义的窗体样式MessageBox控件
- Table &#39;.\mysql\proc&#39; is marked as crashed and should be repaired 报错
- Join-Path(拼接路径)
- 《University Calculus》-chape5-积分法-微积分基本定理
- Android 数据库加密
- javascript 中 function bind()
- iPhone Info.plist属性说明
- break的标签的用法
- Flask 扩展 自定义扩展
- C# 动态调用WebService 3
- ORM杂记
- Java设计模式学习记录-备忘录模式
- bzoj 3673 可持久化并查集 by zky
- Maven构建项目速度太慢的解决办法