0

I am trying to make a very simple script in powershell to create a Certificate using makecert.exe tool (I know powershell already has its own certificate creation method but I would like to use makecert).

I would like to reproduce this command:

makecert.exe -sk server -sky exchange -pe -n CN=<machineName> -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My <certificate path>

How is it possible in powershell?

1
  • That command line string looks like it would work. Are you getting an error message? If so, could you add it to your question? Commented Sep 2, 2014 at 21:39

2 Answers 2

4

For most executables, you want to pass the arguments as an array including the switches. Here is an example:

$arguments = "$env:windir\", 'c:\jpegs\','*.jpg', '/R:0', '/S', '/XD', '*winsxs*'  
Robocopy.exe $arguments 
Sign up to request clarification or add additional context in comments.

5 Comments

I'm sorry, I misunderstood the question. And now I cannot undo it (unless you edit the answer) :(
Thanks MrTux, appreciate the response.
I'm not sure ggui, it seems valid to me. I upvoted it.
FWIW this is unnecessarily hard. The following works just fine in PowerShell: robocopy $env:windir c:\jpegs *.jpg /R:0 /S /XD *winsxs*
Yes it is not needed for robocopy, but as stated in the answer, this was an example. Robocopy is available on every server newer than 2003 so it is easily tested to confirm this method works. Many executables will not allow you to directly pass the arguments like that.
3

If you're on V3 or higher, you should consider using the Stop Parsing operator --%. In this way you can specify parameters just like you would in cmd.exe:

makecert.exe --% -sk server -sky exchange -pe -n CN=acme.com -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My C:\test.cer

Although, now that I look at this, it would probably work just fine like this:

makecert.exe -sk server -sky exchange -pe -n CN=acme.com -ir LocalMachine -is Root -ic MyCA.cer -sr LocalMachine -ss My C:\test.cer

I don't see any characters($,@,(,;) that would cause problems for PowerShell. Passing through of quotes can also be a problem but I don't see any quoting in this case.

2 Comments

Where is the --% operator documented? I didn't find it in in about_Operators.
It is documented in the about_Parsing topic.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.