2017-08-29 31 views
-1

虽然这Powershell PSScriptRoot is null(粘贴在下面的一个简单的阅读)似乎回答这个问题,它不在我的情况。

您必须确保此表达式位于保存的.ps1脚本中。

这可以发生在下列情况:

您使用此语句在PowerShell中ISE控制台您使用PowerSehll控制台这个 声明没有一个脚本文件,您在PowerShell中ISE

只标 这个表达式执行

我在ISE外运行.ps1文件中的ps,仍然得到一个空指针。

+2

PowerShell v2中的'$ PsScriptRoot'只能在.psm1脚本模块文件中使用,但不能在.ps1普通脚本文件中使用。 – PetSerAl

+0

[我如何获得PowerShell脚本的文件系统位置?](https://stackoverflow.com/questions/3667238/how-can-i-get-the-file-system-location-of- A-的PowerShell脚本) – BenH

回答