SFC_K
SFC_K

Reputation: 1

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.

Upvotes: 0

Views: 159

Answers (1)

marsze
marsze

Reputation: 17035

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.

Upvotes: 2

Related Questions