gpt4 book ai didi

c# - 从 C# 调用 powershell 脚本时包含脚本不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:49 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com