64ビットまたは32ビットのmsiがインストールされているかどうかを調べるpowershell関数を記述しました。私たちはビットレート情報を持っているので、Outlookのレジストリキーをチェックしています。64ビットまたは32ビットのExcelがPowershell経由でインストールされているかどうかを調べるには?
ただし、OutlookなしでExcelのみをインストールする場合、このレジストリキーは信頼できません(64ビットOSでは使用可能ですが、32ビットOSでは使用できません)。
私たちがそれを見つけるために書いた関数は次のとおりです。レジストリキーが利用できないので、それは機能しません。私たちが優秀さのビットを見つけることができる他の方法はありますか?
Function Get-OfficeVersionInstalled
{
$NoExcelInstalled = '0'
$excelApplicationRegKey = "HKLM:\SOFTWARE\Classes\Excel.Application\CurVer"
if(Test-Path $excelApplicationRegKey)
{
$excelApplicationCurrentVersion = (Get-ItemProperty $excelApplicationRegKey).'(default)'
#Get version number alone from registry value
$($excelApplicationCurrentVersion -replace "Excel.Application.","")
}
else
{
$NoExcelInstalled
}
}
Function Test-Excel2013AndAbove
{
Param
(
[ValidateSet("x64", "x86")]
$Edition="x64"
)
$isExpectedEditionInstalled = $false
$officeVersion = Get-OfficeVersionInstalled
$office2013Version = 15
if($officeVersion -ge $office2013Version) {
# In registry, version will be with decimal
$officeVersion = $officeVersion+".0"
# Outlook key is having bitness which will decide the edition.
# Even if outlook is not installed this key will be present.
# This is the only place where we can reliably find the edition of Excel
$OutlookKey = "HKLM:\SOFTWARE\Microsoft\Office\$officeVersion\Outlook"
$OutlookWow6432NodeKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\$officeVersion\Outlook"
if(Test-Path $OutlookKey)
{
$officeRegKey = $OutlookKey
}
else
{
$officeRegKey = $OutlookWow6432NodeKey
}
$BitNess = (Get-ItemProperty $officeRegKey).BitNess
if($BitNess -eq $Edition)
{
$isExpectedEditionInstalled = $true
}
else
{
$isExpectedEditionInstalled = $false
}
}
return $isExpectedEditionInstalled
}
キーが存在しない場合は、表示からエラーを停止し続けるために、あなたのREGのquerysの終わりに-ErrorAction SilentlyContinueというを使用することができますが。例 - $ Reg32Key = Get-ItemProperty -path "HKLM:¥SOFTWARE¥Microsoft¥Windows¥CurrentVersion¥Uninstall¥Google Chrome" -name "Version" -ErrorAction SilentlyContinue –