2
當檢索一臺計算機的操作系統,我得到了不同的結果,這取決於我是否如果使用的語句或開關:powerwshell IF VS交換機
if (((Get-WmiObject -ComputerName DT-04 Win32_OperatingSystem).Caption.ToString()) -match "Microsoft Windows 7 Professional") { "Found" } Else { "Not found" }
結果=找到
switch ((Get-WmiObject -ComputerName DT-04 Win32_OperatingSystem).Caption.ToString()) { "Microsoft Windows 7 Professional" { "Found" } Default { "Not Found" } }
結果=未找到
這是爲什麼?
謝謝。它確實看起來好像在返回的字符串後面有一個空格,我發現它是: '「'+(Get-WmiObject -ComputerName DT-04 Win32_OperatingSystem).Caption.trim()+'''' 感謝您的幫助! – cswalker
正確和非常好的解釋答案應該通過檢查它而得到尊重。 – LotPings