简体   繁体   中英

How to make a batch file run a powershell script

I have two commands, listed below: Start “C:\Windows\System32\WindowsPowerShell\v1.0” powershell.exe

Get-ChildItem Cert:\CurrentUser\My | Remove-Item

By themselves, each will run individually, but not together. I can run the top command as a batch file to startup PowerShell, no issues. I can run the second command within Powershell, no issues. Ultimately what I am trying to get is a batch file with simple double-click execution that will remove certs from the personal folder. Can anyone help me tailor these codes to work together? My experience in this is elementary at best so please bear with me. I found a couple of similar issues through online research but nothing I could understand or apply to my situation based upon my level of knowledge on the matter.

You can pass a command using the -Command option:

powershell.exe -Command "Get-ChildItem Cert:\CurrentUser\My | Remove-Item"

But it might be better to pass a filename to a script using the -File switch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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