【发布时间】:2022-01-22 10:55:50
【问题描述】:
我对这段代码有疑问。它打印“x86 操作系统”,即使写入主机 $OSArchitecture 声明架构是 64 位。
$OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture -ErrorAction Stop).OSArchitecture
write-host = $OSArchitecture
if ($OSArchitecture -eq '*64*')
{
Write-Host "x64 operating system"
$Version = Get-ChildItem hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {
$_.DisplayName -Eq 'Microsoft Lync 2013'} | Select-Object DisplayVersion
}
else
{
Write-Host "x86 operating system"
$Version = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Where-Object {
$_.DisplayName -Eq 'Microsoft Lync 2013'} | Select-Object DisplayVersion
}
更新:
我收到此错误:Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Int32"。
【问题讨论】:
-
您不能将通配符与
-eq运算符一起使用。您可以使用-like '*64*'或-match '64'。 -
如果你要使用通配符(*),那么操作符应该是
-Like而不是-eq。 -
我仍然得到:无法将“System.Object[]”类型的“System.Object[]”值转换为“System.Int32”类型。在 line:6 char:21
-
如果我删除 Wow6432Node,它确实有效.. 有什么想法吗?
-
@Bendo1984 你能在你的问题中添加完整的错误吗?
标签: powershell