What I am trying to do:
Use a .bat file to call a .ps1 file (don't ask) that generates a self-signed certificate and key pair (.pem), then the .bat file will move each .pem to a new directory.
What I have done:
I have the .ps1 file working correctly, it generates both files, but it does require PowerShell to be run as administrator. I have the .bat file calling the .ps1 file when it should. Within the batch file, I am opening PowerShell, which then opens another PowerShell instance as administrator (because there is no way to run PS as admin from the command line, correct me if I'm wrong). Here is the line of code:
PowerShell -Command "& {Start-Process PowerShell -ArgumentList '-NoExit -File ""cert-gen.ps1""' -Verb RunAs}"
What is happening:
When this line is run, I see a PS window pop up and immediately close and it does not generate my cert and key. Since it is closing immediately, I cannot see if there any error within that window, and the command line does show any errors. I am pretty sure I have -NoExit in the correct place.
Bonus:
This needs to be fully automated with no user interaction, so the prompting for UAC elevation is not going to work. I eventually need to figure out a way around this as well, so if there is a solution that fixes all of these problems in one go, that is even better!
CMD.exe(a command line interface) to start aPowerShell.exesession (another command line interface) where you start anotherPowerShell.exesession (again another command line interface). Sorry, but I cannot "(don't ask)" ... 🤷🏼♂️🤔PowerShell -File "cert-gen.ps1"and the .ps1 is doing what it's supposed to do. Now my only hang-up is that I'm not sure if the previous scripts in the chain are launched as admin. I don't think they are. But regardless, this gets me back on track. Thank you!