条件为真,但返回false

时间:2016-10-17 20:34:52

标签: powershell

调试时,$var不等同于“folder\that\isNot\equivalent\".

我尝试将其更改为等效语句,但它无效。任何见解都将不胜感激。

以下是所有相关代码:

$process = "Explorer++.exe"
$var = Get-WmiObject Win32_Process -Filter "name = '$process'" | select -expandproperty CommandLine
$var = $var -split '\\\\' | select -Last 1
Write-Host $var
if ($var  -ne "folder\that\isNot\equivalent\")
{
    Stop-Process -processname explorer++
    Stop-Process -processname curProc
}
else
{
    return $true
}

1 个答案:

答案 0 :(得分:1)

问题是围绕$ var的空白。我使用了命令$var = $var -replace "\s",""

用空字符串替换每个空格符号,我也将其更改为等效语句。

if ($var -eq "\folder\that\is\")