简体   繁体   English

如何用批处理/ cmd启动PS脚本文件?

[英]How to start a PS script file with a batch/cmd?

I have a Power Shell script file (it's PS5 on Win10) that allow me to change to a specific wallpaper when I execute it. 我有一个Power Shell脚本文件(在Win10上为PS5),可以在执行该文件时将其更改为特定的墙纸。 I can only do that if I have administrator access. 只有拥有管理员权限,我才能这样做。 There are ways work around like making a .bat file 有一些解决方法,例如制作.bat文件

powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file "C:\Users\name\wallp1.ps1"

But it seems that method will change execution policy permanently to unrestricted which is really unsecure What I want is to be able to execute a PS script through Task Scheduler (it must be through that not through Startup folder). 但是似乎该方法将永久性地将执行策略更改为不受限制,这确实是不安全的。我想要的是能够通过Task Scheduler(必须通过而不是通过Startup文件夹)执行PS脚本。 I want to be able to change Wallpaper on a specific time and only Task Scheduler can do that. 我希望能够在特定时间更改墙纸,只有Task Scheduler可以做到。 Unless I can do that with command or batch files. 除非我可以使用命令或批处理文件来做到这一点。

In short: I want to run a PS script through another file without messing with current Execution Policy 简而言之:我想通过另一个文件运行PS脚本而又不弄乱当前的执行策略

Other method seems not work: how to run PowerShell Script when computer starts? 其他方法似乎不起作用: 计算机启动时如何运行PowerShell脚本?

Or maybe there is a way to be able to revert back to default execution policy after the PS script has ran? 还是有一种方法可以在PS脚本运行后恢复为默认执行策略? It must be done automatically in one file 必须在一个文件中自动完成

Using the launch command you provided does not change the execution policy permanently on the host. 使用您提供不会永久更改主机上的执行策略的启动命令。 Tested on Win10 with PS5. 在Win10上使用PS5测试。

Second most upvoted powershell question on SO 第二个最upvoted powershell问题上SO

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM