我有一个 power shell 脚本,其中包含脚本,如下所示。
. "$PSScriptRoot\CheckPermissions.ps1"
当从 c# 调用脚本时,我收到此错误
{The term '\CheckPermissions.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.}
从 PS 窗口运行时,脚本运行良好。
从 C# 运行脚本时 $PSScriptRoot 变量不可用吗?
最佳答案
您可以尝试使用以下命令来获取脚本目录:
$scriptDir = Split-Path $script:MyInvocation.MyCommand.Path
请注意,返回的文件夹路径将以反斜杠 (\
) 结尾。
关于c# - 从 C# 调用 powershell 脚本时包含脚本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30616013/