0
I have currently just followed an excellent stackoverflow answer to create a new self-signed certificate so I can run my Powershell profile script in AllSigned mode.
This has worked ok but after having done this a few times (I had found other guides previously) I was thinking about simplifying the process (I understand there are many automation options out there), and wanted to add it to $env. If I do this,:
$env:sscert = $selfsigncert
where $selfsigncert
is of type: System.Security.Cryptography.X509Certificates.X509Certificate
$env:sscert.GetType()
returns System.Object
.
I have garnered from this guide that the below code is how to set a permanent $env variable, not $env:sscert as above, but I want to make sure the value is correct before I commit to that
[Environment]::SetEnvironmentVariable("TestVariableName", "My Value", "<option>")
Alternatively if this is a terrible idea security-wise I'd appreciate the warning
Environment variables are strings. To store your certificate in a permanent environment variable you'll need to convert the object to string (deserialize). And then restore it back. Why don't just save it in a file? – montonero – 2019-01-10T09:20:34.333
It was getting frustrating writing out the path to the cert but saving in a file could work yes, after you ask that very logical question though it has just made me realise I can just save the path as an environment variable and use
Get-Item
– Scott Anderson – 2019-01-10T18:37:08.203Wait I just realised that I can't do that I don't think unless I index the return of a gci call - what do you mean about saving a file? – Scott Anderson – 2019-01-10T19:40:52.913
You can use Export-Certificate as described here http://woshub.com/how-to-create-self-signed-certificate-with-powershell/ to save to a file.
– montonero – 2019-01-11T10:47:12.257