Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何验证用户在正确的目录中?_Powershell_Powershell Ise - Fatal编程技术网

Powershell 如何验证用户在正确的目录中?

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

嘿,伙计们,我正在写一个快速脚本,就在它进入if块之前,我需要确保用户在Documents文件夹中

如果($pwd-非$DocumentsPath)

这是我使用的条件,但我不断得到一个错误,它指出:

表达式或语句中出现意外标记“-not”。 第12行字符:14

表达式或语句中出现意外标记“DocumentsPath”。
在第12行char:19

您不需要
-not
运算符,该运算符用于执行此操作,就像将
$false
转换为
$true
一样。您想要的是“不相等”或
-ne

if ($pwd -ne $DocumentsPath)

,以便在将来帮助您。

您必须指定“路径”属性

if($PWD.Path -ne $DocumentsPath) {...}

if(!$PWD.Path.Trim($DocumentsPath)) {...}