– 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)
 

来自


[PowerShell]–Checking the version of Office installed的更多相关文章

  1. java compiler level does not match the version of the installed java project facet 解决方案

    项目出现 java compiler level does not match the version of the installed java project facet 错误,一般是项目移植出现 ...

  2. java compiler level does not match the version of the installed java project facet

    Java compiler level does not match the version of the installed java project facet错误的解决 因工作的关系,Eclip ...

  3. Java compiler level does not match the version of the installed Java project facet.(转)

    Java compiler level does not match解决方法 从别的地方导入一个项目的时候,经常会遇到eclipse/Myeclipse报Description  Resource P ...

  4. maven项目 Java compiler level does not match the version of the installed Java project facet

    因工作的关系,Eclipse开发的Java项目拷来拷去,有时候会报一个很奇怪的错误.明明源码一模一样,为什么项目复制到另一台机器上,就会报“java compiler level does not m ...

  5. Java compiler level does not match the version of the installed Java project facet.问题

    从同事那里拷贝过来的web项目,导入到eclipse中,出现Java compiler level does not match the version of the installed Java p ...

  6. Java compiler level does not match the version of the installed Java project facet. springmvc1 和 Target runtime Apache Tomcat v7.0 is not defined.

    Java compiler level does not match the version of the installed Java project facet.springmvc1 : Targ ...

  7. eclipse中切换jre后报错:Java compiler level does not match the version of the installed Java project facet.

    项目移除原来的jre环境lib后,添加本地的jre,报错如下: Java compiler level does not match the version of the installed Java ...

  8. 解决Java compiler level does not match the version of the installed Java project facet.问题

    其实之前遇到过Java compiler level does not match the version of the installed Java project facet.这个问题,因为当时没 ...

  9. 转:Java compiler level does not match the version of the installed Java project facet

    a.问题描述:eclipse加载新的项目后报一个错误,具体描述如下: Description Resource PathLocation Type Java compiler level does n ...

随机推荐

  1. 双线机房双网卡双ip 路由设置

    做互联网网站,最头疼的事情之一就是电信和网通的互联互不通了,为了能够让北方网通和南方电信用户都可以快速的访问网站,解决办法就是托管 到双线机房.双线机房有两类,一类是通过BGP技术实现互联互通,服务器 ...

  2. JavaNIO - AbstractInterruptibleChannel

    1. 描述 可异步关闭和中断的Channel. (1)实现InterruptibleChannel接口的Channel支持异步关闭:如果一个线程IO阻塞在一个可中断的channel,另一个线程可以执行 ...

  3. Atitit.http连接合并组件   ConnReducerV3 新特性

    Atitit.http连接合并组件   ConnReducerV3 新特性 D:\0workspace\AtiPlatf_cms\src\com\attilax\util\ConnReducerV2. ...

  4. NSArray、NSMutableArray和NSMutableDictionary的用法

    转自:http://www.cnblogs.com/wangpei/admin/EditPosts.aspx?opt=1 NSArray是静态的数组,就是它所指向的内容是不可改变的,它指向一段内存区域 ...

  5. myeclipse之完全破解

    并不是所有的破解都是成功的,就如并不是所有的战争都会胜利一样,我们在做事情的时候,总会遇到些问题,比如Activate不成功,需要手动激活. 激活不成功就是不成功,来回的破解.卸载.重装,都还是不可能 ...

  6. 解决/usr/bin/ld: cannot find -lssl

    一般情况下,-lssl表示要寻找库 libssl.so, 而上面的错误表示ld找不到这个库,一般情况下,原因是系统中没有安装这个库,只要安装就好了. 可以先使用sudo apt-cache searc ...

  7. 由于没有发现潜在的递归导致MySQL链接数溢出:MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connec

    DAOProxy的代码:下面代码中红色高亮的就是出问题的地方,DAOFactory中会构造一个PersonDAOProxy,调用listPersons或者addPerson显然会导致递归,从而导致My ...

  8. hdu 1018 Big Number 数学结论

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. linux学习笔记22--命令ln

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在 ...

  10. linux查看硬盘空间 文件大小

    du,disk usage,是通过搜索文件来计算每个文件的大小然后累加,du能看到的文件只是一些当前存在的,没有被删除的.他计算的大小就是当前他认为存在的所有文件大小的累加和 df,disk free ...