Replacing a certificate using the Octopus.Client / Powershell doesn't work

I’m trying to replace a certificate (hooking it into the let’s encrypt flow) and I get the following exception:

The document does not define a link for 'Replace'

The code used:

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint("", $OctopusApiKey)
$repository = New-Object Octopus.Client.OctopusRepository($endpoint);
$certificateToReplace = New-Object Octopus.Client.Model.CertificateResource($certName, '', '');
$certificateToReplace.Name = $certName;
$certificateData = Get-Content "C:\\Certificates\\$suffix.pfx" -Encoding Byte
$password = "";
$certDataBase64 = [System.Convert]::ToBase64String($certificateData);
$newCert = New-Object Octopus.Client.Model.CertificateResource( $certName , $certDataBase64 , $password ) 
$result = $repository.Certificates.Replace($certificateToReplace, $certDataBase64, $password);

Any thoughts? Browsed around in the code a bit but couldn’t figure it out.

Hi there

Thanks for getting in touch! Sorry for the delay in getting back to you.

Looking at your code there, I believe the issue is that you are creating a Octopus.Client.Model.CertificateResource yourself, rather than using one retrieved from the repository.

So, instead of going:

$certificateToReplace = New-Object Octopus.Client.Model.CertificateResource($certName, '', '');
$certificateToReplace.Name = $certName;


$certificateToReplace  = $repository.Certificates.FindByName($certName)

I believe this should work.

Have a go with that, and let me know how you get along.


Hi Matt,

Sorry for the late response, just got back from a long business trip.
Confirmed it working when retrieving the certificate like that, now I can start migrating all let’s encrypt scripts to update a corresponding octopus certificate, great.