我可以使用“运行 PowerShell 脚本”将 powershell 版本更改为 7对 Power Automate Desktop 执行操作?

发布于 2025-01-17 23:31:05 字数 555 浏览 5 评论 0原文

我可以在“运行 PowerShell 脚本”操作中将 powershell 版本更改为 7 吗? 如果可以的话,怎样做?

我知道这篇文章,但我找不到是否可以更改 PAD 执行版本。 https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Powershell-and-other-script-SUPPORTED-VERSION/td-p/1501322

我已经安装了 powershell version7。 我想在“Export-Csv”上使用“-UseQuotes”选项。

仅供参考,我的 PS 版本在这里。 PSVersion 5.1.19041.1320

谢谢,

我还检查了有关 PAD 的注册表,但没有注册表来管理 powershell

Can I change powershell version to 7 on "Run PowerShell script" action?
If I can, how?

I know this post but I couldn't find if I can change the version PAD execute.
https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Powershell-and-other-script-SUPPORTED-VERSION/td-p/1501322

I already installed powershell version7.
I'd like to use "-UseQuotes" option on "Export-Csv".

FYI, my PSVersion is here.
PSVersion 5.1.19041.1320

Thank you,

I also checked registry about PAD but There is noregistry to manage powershell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏九 2025-01-24 23:31:05

这有点难看,但它会完成工作。

我有这个非常基本的流程,它只是运行 PS 脚本并将结果输出到消息框中。

流

将其放入 PowerShell 任务中,然后查看输出。

$psVersion = (Get-Host).Version.Major

if ($psVersion -ne 7) {
    $processInfo = New-Object System.Diagnostics.ProcessStartInfo

    $processInfo.FileName = "C:\Program Files\PowerShell\7\pwsh.exe"
    $processInfo.RedirectStandardError = $true
    $processInfo.RedirectStandardOutput = $true
    $processInfo.UseShellExecute = $false
    $processInfo.Arguments = $MyInvocation.MyCommand.Definition

    $process = New-Object System.Diagnostics.Process
    $process.StartInfo = $processInfo
    $process.Start() | Out-Null
    $process.WaitForExit()

    $stdout = $process.StandardOutput.ReadToEnd()
    $stderr = $process.StandardError.ReadToEnd()

    Write-Host $stdout
} else {
    # Your logic goes here!
    Write-Host "PowerShell Version = $psVersion"  
}

你应该得到这个...

Result

本质上,它会检查版本,如果不是版本 7,它将启动 PowerShell 7,然后检索输出。

记下 PS7 的文件路径,您可能需要更改它,或者您可以简化它。我已经采用了完整路径以确保它有效。

This is a bit ugly but it will get the job done.

I have this very basic flow, it just runs the PS script and outputs the results in a message box.

Flow

Throw this into the PowerShell task and then view the output.

$psVersion = (Get-Host).Version.Major

if ($psVersion -ne 7) {
    $processInfo = New-Object System.Diagnostics.ProcessStartInfo

    $processInfo.FileName = "C:\Program Files\PowerShell\7\pwsh.exe"
    $processInfo.RedirectStandardError = $true
    $processInfo.RedirectStandardOutput = $true
    $processInfo.UseShellExecute = $false
    $processInfo.Arguments = $MyInvocation.MyCommand.Definition

    $process = New-Object System.Diagnostics.Process
    $process.StartInfo = $processInfo
    $process.Start() | Out-Null
    $process.WaitForExit()

    $stdout = $process.StandardOutput.ReadToEnd()
    $stderr = $process.StandardError.ReadToEnd()

    Write-Host $stdout
} else {
    # Your logic goes here!
    Write-Host "PowerShell Version = $psVersion"  
}

You should get this ...

Result

Essentially, it's checking for the version and if it's not version 7, it will launch PowerShell 7 and then retrieve the output.

Take note of the file path for PS7, you may need to change that or you may be able to simplify it. I've gone with the full path to make sure it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文