Powershell 如何验证用户在正确的目录中?
嘿,伙计们,我正在写一个快速脚本,就在它进入if块之前,我需要确保用户在Documents文件夹中 如果($pwd-非$DocumentsPath) 这是我使用的条件,但我不断得到一个错误,它指出: 表达式或语句中出现意外标记“-not”。 第12行字符:14 表达式或语句中出现意外标记“DocumentsPath”。Powershell 如何验证用户在正确的目录中?,powershell,powershell-ise,Powershell,Powershell Ise,嘿,伙计们,我正在写一个快速脚本,就在它进入if块之前,我需要确保用户在Documents文件夹中 如果($pwd-非$DocumentsPath) 这是我使用的条件,但我不断得到一个错误,它指出: 表达式或语句中出现意外标记“-not”。 第12行字符:14 表达式或语句中出现意外标记“DocumentsPath”。 在第12行char:19您不需要-not运算符,该运算符用于执行此操作,就像将$false转换为$true一样。您想要的是“不相等”或-ne if ($pwd -ne $Docu
在第12行char:19您不需要
-not
运算符,该运算符用于执行此操作,就像将$false
转换为$true
一样。您想要的是“不相等”或-ne
if ($pwd -ne $DocumentsPath)
,以便在将来帮助您。您必须指定“路径”属性
if($PWD.Path -ne $DocumentsPath) {...}
或
if(!$PWD.Path.Trim($DocumentsPath)) {...}