简体   繁体   English

Powershell Win32_OperatingSystem选择标题与操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”进行比较导致错误的结果

[英]Powershell Win32_OperatingSystem select Caption compare with OS Version 'Microsoft Windows Server 2008 R2 Enterprise' resulting wrong result

When I try to compare my OS version 'Microsoft Windows Server 2008 R2 Enterprise' with Win32_OperatingSystem select caption result it is resulting false. 当我尝试将操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”与Win32_OperatingSystem选择字幕结果进行比较时,结果为false。

Example: 例:

$Server='Computername' #Computername which has OS Version 'Microsoft Windows Server 2008 R2 Enterprise'
$OSVersion = Invoke-command -computername $Server -scriptblock {Get-WmiObject -class Win32_OperatingSystem | select Caption}
#OS Version comparing with Win32_OperatingSystem caption
If ($OSVersion.Caption -eq 'Microsoft Windows Server 2008 R2 Enterprise')
{
Write-Host 'True'
}
Else
{ Write-Host 'False'}

Result: 结果:

False

But it should result True. 但这应为True。 Could someone explain why it is resulting false even my OS Version and select caption is correct. 有人可以解释为什么即使我的操作系统版本和选择的标题正确也导致错误。

If you run this command 如果运行此命令

Get-WmiObject -class Win32_OperatingSystem -ComputerName insert the computername | select Caption

Is the result really Microsoft Windows Server 2008 R2 Enterprise ? 结果真的是Microsoft Windows Server 2008 R2 Enterprise吗?

if i run you script like this on my computer 如果我在计算机上运行这样的脚本

$Server='laptop090' #Computername which has OS Version 'Microsoft Windows Server 2008 R2 Enterprise'
$OSVersion = Get-WmiObject -class Win32_OperatingSystem -ComputerName $Server | select Caption
#OS Version comparing with Win32_OperatingSystem caption
If ($OSVersion.Caption -eq 'Microsoft Windows 10 Pro Insider Preview')
{
Write-Host 'True'
}
Else
{ Write-Host 'False'}

it work 这行得通

I executed below script to know why it is resulting 'False' for OS Version 'Microsoft Windows Server 2008 R2 Enterprise' 我执行了以下脚本,以了解为什么操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”会产生“ False”

$Server='ComputerName'
$OSVersion = 'Microsoft Windows Server 2008 R2 Enterprise'
$OSVersionCaption = Invoke-command -computername $Server -scriptblock {Get-WmiObject -class Win32_OperatingSystem | select Caption}
$OSVersionCaption.Caption.length
$OSVersion.length

Result:
43
44

I really surprised by seeing the result. 看到结果,我真的很惊讶。 Length is not matching and found there was a space at the end of OS Version 'Microsoft Windows Server 2008 R2 Enterprise ' caused this issue. 长度不匹配,并且发现操作系统版本'Microsoft Windows Server 2008 R2 Enterprise'的末尾有空格导致此问题。 This issue is occured only for the OS Version 'Microsoft Windows Server 2008 R2 Enterprise' and not for the other OS Version. 仅对于操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”,而不对于其他操作系统版本,才会发生此问题。

Conclusion there is no issue with the below command. 结论以下命令没有问题。 Issue with the OS Version 'Microsoft Windows Server 2008 R2 Enterprise' 操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”的问题

Get-WmiObject -class Win32_OperatingSystem | select Caption

Could someone try for OS version 'Microsoft Windows Server 2008 R2 Enterprise' and confirm. 有人可以尝试使用操作系统版本“ Microsoft Windows Server 2008 R2 Enterprise”并进行确认。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 cordova 安装错误 - 命令失败:powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption 术语“Get-CimInstance”不是重新 - cordova installation error -Command failed: powershell (Get-CimInstance -ClassName Win32_OperatingSystem).caption The term 'Get-CimInstance' is not re PowerShell-Win32_OperatingSystem中的Select-Object显示异常 - PowerShell - Select-Object from Win32_OperatingSystem displays rather oddly Powershell GWMI win32_operatingsystem 修剪输出 - Powershell GWMI win32_operatingsystem trim output 是否会为在Win Server 2008 R2上运行的Windows 7开发PowerShell脚本? - Will a PowerShell script developed for a Windows 7 run on Win Server 2008 R2? CIM,Win32_OperatingSystem和Win32ShutdownTracker - CIM, Win32_OperatingSystem, and Win32ShutdownTracker 将Win32_OperatingSystem的CountryCode转换为国家/地区字符串 - Convert CountryCode of Win32_OperatingSystem to the country string Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? - Get-CimInstance -ClassName Win32_bios, Win32_operatingsystem,? Windows Server 2008 R2 PowerShell和Internet Explorer 9 - Windows Server 2008 R2 PowerShell and Internet Explorer 9 使用Powershell Windows Server 2008 R2将用户导入本地 - Import users to local with powershell windows server 2008 r2 更改芬兰语Windows Server 2008 R2上Powershell脚本的文化 - Change culture on Finnish Windows Server 2008 R2 for Powershell Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM