[英]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.