简体   繁体   English

通过命令行或 powershell 5.1 调用时,Powershell 7.2 操作不起作用

[英]Powershell 7.2 actions not working when called via command line or powershell 5.1

I am working on a scheduled restart toasts using the Burnt Toast module.我正在使用 Burnt Toast 模块进行计划的重启敬酒。 To add a selection box to have them schedule a time to do the restart(1 hour, 2 hours, etc..) and handle the action events, I need Powershell 7.1 or above.要添加一个选择框让他们安排时间进行重启(1 小时、2 小时等)并处理操作事件,我需要 Powershell 7.1 或更高版本。 I have code that works when I run it directly from powershell 7.2.当我直接从 powershell 7.2 运行它时,我的代码可以工作。

The issue I have is that when we send this to our user's computers, the script will run in powershell 5.1, not 7.2.我遇到的问题是,当我们将其发送到用户的计算机时,脚本将在 powershell 5.1 中运行,而不是 7.2。 No way we can change that.我们无法改变这一点。 I get a message saying "Toast events are only supported on Powershell 7.1.0 and above. Your notification will still be displayed, but the actions will be ignored."我收到一条消息“仅 Powershell 7.1.0 及更高版本支持 Toast 事件。您的通知仍会显示,但操作将被忽略。” And like it says, it displays the toast but does not do the action.就像它说的那样,它显示吐司但不执行操作。

What I am trying to do now is use either powershell 5.1 or command script to call powershell 7.2 so the script can run that way.我现在要做的是使用 powershell 5.1 或命令脚本来调用 powershell 7.2 以便脚本可以这样运行。

In powershell 5.1, I am running this command: Invoke-Expression -Command "C:'Program Files'\PowerShell\7\pwsh.exe -Command C:\Setup\Scripts\ScheduledRestartToast.ps1"在 powershell 5.1 中,我正在运行以下命令: Invoke-Expression -Command "C:'Program Files'\PowerShell\7\pwsh.exe -Command C:\Setup\Scripts\ScheduledRestartToast.ps1"

In command script, I am running this command: "c:\Program Files\PowerShell\7\pwsh.exe" -command "c:\Setup\Scripts\ScheduledRestartToast.ps1"在命令脚本中,我正在运行以下命令:“c:\Program Files\PowerShell\7\pwsh.exe”-command “c:\Setup\Scripts\ScheduledRestartToast.ps1”

Both of these display the toast, but neither of them actually does the action.这两个都显示吐司,但它们都没有实际执行操作。

Is it possible to have Powershell 7 run actionable scripts this way?是否可以让 Powershell 7 以这种方式运行可操作的脚本?

Thanks谢谢

I found that If I do this instead:我发现如果我这样做:

$ConsoleCommand = "C:\Setup\Scripts\ScheduledRestartToast.ps1" $ConsoleCommand = "C:\Setup\Scripts\ScheduledRestartToast.ps1"

Start-Process pwsh -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -WindowStyle Hidden启动进程 pwsh -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -WindowStyle Hidden

it will keep the window open until they perform the action.它将使 window 保持打开状态,直到他们执行操作。

Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Invoke-Command 调用命令时 PowerShell 不一致 - Inconsistent PowerShell when command is called via Invoke-Command PowerShell - 从 Invoke-Command 内部调用时,ShouldProcess 不起作用 - PowerShell - ShouldProcess not working when called from inside Invoke-Command 如何在 PowerShell 5.1 中将命令行应用程序输出输出到后台变量? - How to get command line application output to a variable in background in PowerShell 5.1? 通过命令行将变量传递给 powershell 脚本 - Passing a variable to a powershell script via command line 通过Windows命令行和Powershell对页面进行基准测试 - Benchmark A Page Via Windows Command Line and Powershell 从PowerShell脚本调用时,MSBuild使用.sln;而从命令行调用时,则使用.csproj - MSBuild uses .sln when called from PowerShell script but .csproj when called from command line Powershell 变量替换不能从命令行工作 - Powershell Variable replacement not working from command line 在Powershell中更改被调用的命令 - Changing called command in Powershell 更改 Powershell 7.2 默认工作目录 - Changing Powershell 7.2 default working directory Powershell Copy-item命令在脚本中不起作用,尽管在从命令行运行时确实起作用 - Powershell Copy-item command not working in script although it does work when run from a command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM