Encrypting Password or text using Certificate's

Modified on Sun, 15 Jan, 2023 at 10:01 PM


1. create a certificate on a domain controller.

2. export the certificate as a .pfx, when asked to specify password, choose permissions instead and allow only 'domain computers' access

3. Create the secured message or password using the certificate you created using the below command:


"Secret Texr" | Protect-CmsMessage -To cn=secret -OutFile .\Desktop\secret.txt


4. save the secret.txt file along with the certificate into a folder of your choosing, in this example, you could store in the netlogin folder to change a bunch of clients local admin password. 


5. run the following as a .PS1 at startup on a machine to change the local admin on a client using GPO:

Import-pfxCertificate -FilePath \\rwfs.romanway.worcs.sch.uk\netlogon\Scripts\VivaCert\VivaLapassword.pfx -CertStoreLocation cert:\localmachine\my


$password = ConvertTo-SecureString (Unprotect-CmsMessage -Path  \\rwfs.romanway.worcs.sch.uk\netlogon\Scripts\VivaCert\secret.txt) -AsPlainText -Force


set-localuser -name Administrator -password $password

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article