1

We have a certificate server from which users are able to download their certificate (User Template) from this URL: http://localhost/certsrv.

I now want to create a script which will do the following:

  1. Delete the existing certificate from Personal Certificate store.
  2. Install the new certificate in Personal certificate store.

I already made the script, and it is able to delete the certificate but installation is not happening because the command is not supporting in Windows 7.

Here is my code:

# User Details
$dom = $env:userdomain
$usr = $env:username
$fulname = ([adsi]"WinNT://$dom/$usr,user").fullname

#get certificate & Remove the certificate
$Cert = Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object {$_.Subject -match "$fulname"} | Remove-Item

#Install new certificate
Get-Certificate -Template User -DnsName mydomain.com -CertStoreLocation cert:\CurrentUser\My
Mark Wragg
  • 236
  • 2
  • 12
  • "Get-Certificate" command is not supporting in windows 7 PowerShell version 4. is there any other way we can install the certificate (like - VBS or other scripts)? – saikat chatterjee Apr 17 '17 at 08:52

1 Answers1

1

I believe you will need to use the command-line tool certutil.exe on Windows 7. It's use is documented here: https://technet.microsoft.com/en-us/library/cc732443(v=ws.11).aspx and available when Certificate Services are installed.

For example:

certutil -addstore -user -f "My" "Path to certificate\certificate.cer"

You can make use of this tool from within a PowerShell script.

Mark Wragg
  • 236
  • 2
  • 12