API Certificate store

Product: PowerShell Universal
Version: 2.6.2

Hey,

We want to use PSU to read / write encrypted columns in several SQL tables, that can then be exposed as an API endpoint.
SQL AlwaysEncrypted is based on certificates, which grants the user access to the clear text data.

Long story short, if i execute this code as an script (both Integrated and specific Powershell versions) it returns the certificate.
But if i execute it as an API endpoint, no data is returned and it just hangs for several minutes.
Fx:

try {
    $Certs = Get-ChildItem -Path cert:\CurrentUser\My\ -erroraction stop
}
catch {
    $_.Execption.message
}
$certs

Is there an way to accomplish this, or is this by design?

That is not by design. It could be the automatic JSON conversion. The ConvertTo-Json cmdlet has an issue where objects that are complex can cause it to hang.

The workaround is to specify a lower depth.

try {
    $Certs = Get-ChildItem -Path cert:\CurrentUser\My\ -erroraction stop
}
catch {
    $_.Execption.message
}
$certs | ConvertTo-Json -Depth 1

We should probably put a timeout setting on API endpoints.

That worked - thanks! :slight_smile:

It would be an good idea to set an default timeout limit, but also let us define / override one.
We have APIs that contact several systems, and it takes approx 10 minutes to query it all - would be annoying, if the hardcoded limit closed the session :slight_smile:

We would add the option but keep the current behavior since enforcing a timeout would be a breaking change for some.