Welcome to FreeSoftwareServers Confluence Wiki

Generate :

@ECHO OFF
pushd %~dp0
cls
::FreeSoftwareServers

set certname=Name
set certstore=Cert:\CurrentUser\My\
set pshell=powershell.exe

%pshell% -c New-SelfSignedCertificate -CertStoreLocation %certstore% -DnsName %certname% -Type CodeSigning -NotAfter (Get-Date).AddMonths(42)
PAUSE

Export PKI:

@ECHO OFF
pushd %~dp0
cls
::FreeSoftwareServers

set certname=NAME
set certfilepath=
set certstore=Cert:\CurrentUser\My\
set pshell=powershell.exe

FOR /F %%N IN ('powershell.exe -c Get-ChildItem  -Path Cert:\CurrentUser\My') DO (
 ECHO "%%N" | FIND /i "%certname%" >nul
 IF %ERRORLEVEL% EQU 0 (
  Set thumbprint=%%N
 )
)

%pshell% -c Export-Certificate -Cert %certstore%%thumbprint% -FilePath '%certfilepath%%certname%.cer'
PAUSE


Export PFX:

@ECHO OFF
pushd %~dp0
cls
::FreeSoftwareServers

set certname=name
set certfilepath=path
set certstore=Cert:\CurrentUser\My\
set protectto="CORP\name"
set pshell=powershell.exe

FOR /F %%N IN ('powershell.exe -c Get-ChildItem  -Path Cert:\CurrentUser\My') DO (
 ECHO "%%N" | FIND /i "%certname%" >nul
 IF %ERRORLEVEL% EQU 0 (
  Set thumbprint=%%N
 )
)

%pshell% -c Export-PfxCertificate -Cert %certstore%%thumbprint% -FilePath '%certfilepath%%certname%.pfx' -ProtectTo %protectto% -Verbose
PAUSE


Share:

@ECHO OFF
pushd %~dp0
cls
::FreeSoftwareServers

set certfilepath=%~dp0\NAME.cer
set trustedpub=Cert:\CurrentUser\TrustedPublisher
set personalcert=Cert:\CurrentUser\My
set trustrootcert=Cert:\CurrentUser\Root
set pshell=powershell.exe

%pshell% -c Import-Certificate -FilePath '%certfilepath%' -CertStoreLocation %trustedpub%
%pshell% -c Import-Certificate -FilePath '%certfilepath%' -CertStoreLocation %personalcert%
%pshell% -c Import-Certificate -FilePath '%certfilepath%' -CertStoreLocation %trustrootcert%
::PAUSE
  • No labels