Saving self-signed cert to $env












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










share|improve this question























  • 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
    Jan 10 at 9:20











  • 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
    Jan 10 at 18:37











  • Wait 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
    Jan 10 at 19:40











  • You can use Export-Certificate as described here woshub.com/… to save to a file.

    – montonero
    Jan 11 at 10:47
















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










share|improve this question























  • 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
    Jan 10 at 9:20











  • 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
    Jan 10 at 18:37











  • Wait 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
    Jan 10 at 19:40











  • You can use Export-Certificate as described here woshub.com/… to save to a file.

    – montonero
    Jan 11 at 10:47














0












0








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










share|improve this question














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







command-line powershell environment-variables certificate file-types






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 10 at 0:41









Scott AndersonScott Anderson

84




84













  • 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
    Jan 10 at 9:20











  • 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
    Jan 10 at 18:37











  • Wait 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
    Jan 10 at 19:40











  • You can use Export-Certificate as described here woshub.com/… to save to a file.

    – montonero
    Jan 11 at 10:47



















  • 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
    Jan 10 at 9:20











  • 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
    Jan 10 at 18:37











  • Wait 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
    Jan 10 at 19:40











  • You can use Export-Certificate as described here woshub.com/… to save to a file.

    – montonero
    Jan 11 at 10:47

















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
Jan 10 at 9:20





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
Jan 10 at 9:20













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
Jan 10 at 18:37





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
Jan 10 at 18:37













Wait 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
Jan 10 at 19:40





Wait 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
Jan 10 at 19:40













You can use Export-Certificate as described here woshub.com/… to save to a file.

– montonero
Jan 11 at 10:47





You can use Export-Certificate as described here woshub.com/… to save to a file.

– montonero
Jan 11 at 10:47










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392521%2fsaving-self-signed-cert-to-env%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1392521%2fsaving-self-signed-cert-to-env%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

Mangá

 ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕