我有一个需要加载powershell配置文件的powershell任务,但我可以看到Azure DevOps中的powershell任务是使用-NoProfile执行的。
C:windowsSystem32WindowsPowerShellv1.0powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted
我们能换一下吗?我需要使用配置文件,以便powershell.exe了解代理信息。
加载powershell配置文件的原因:
- 根据PowerShell代理设置PowerShell代理
如果没有此设置,Connect PnP Online将失败,出现以下异常:
System.Net.WebException无法解析远程名称:"domainname.sharepoint.com">
对于这个问题,azure devops中的power shell任务默认使用-NoProfile
参数执行,这是设计的。powershell任务的源代码在github上是公共的,您可以查看其中定义的参数。
$arguments = "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command `". '$($filePath.Replace("'", "''"))'`""
您可以在我们的UserVoice网站上提交对此功能的请求,该网站是我们提供产品建议的主要论坛。然后你可以投票给建议票,并在那里分享你的评论。如果产品团队查看,他们将提供更新。
此外,作为一种变通方法,您可以使用cmd任务调用powershell来运行ps脚本。这允许您指定在执行过程中需要提供的参数。关于如何在CMD中运行PowerShell,您可以参考此案例。