PDA

View Full Version : [SLEEPER:] Help - Powershell to VBA



aks131
07-09-2024, 04:34 PM
Need help converting this powersheel in VBA code. I am new to VBA , please advise/guide.

#Step 1: Authenticate securily to API Server
$certStore = "CurrentUser"; # Alternative: LocalMachine
$subFieldName = "CN";
$issuedTo = "PS Cloud Authentication, O=APISafe, OU=Development, C=Canada";

#Step 2: "Finding client certificate..";
$certs = Get-ChildItem -Path "cert:\${certStore}\My" -EKU "Client Authentication";
$cert = $certs | Where-Object { $_.Subject -eq "${subFieldName}=${issuedTo}" };
#Write-Output $cert
$cert;
[System.Security.Cryptography.X509Certificates.X509Certificate2]$script:authCert = $cert
Psafe-SignAppIn
#Secure Connection
$baseUrl = https://APISafe/api/public/v3/;
#The Application API Key generated in APISafeInsight
$apiKey = "This is where the API key will be once it is given to you.";
#Username of APISafeInsight user granted permission to the API Key
$runAsUser = "TESTAPI";
$clientCertificateType = "BICertificate";

Aussiebear
07-09-2024, 04:45 PM
Welcome to VBAX aks131. What you are asking is in my belief beyond the capabilities of VBA.

aks131
07-09-2024, 05:34 PM
Welcome to VBAX aks131. What you are asking is in my belief beyond the capabilities of VBA.

Need is to Authenticate cert placed in Windows Cert Store and make rest API Call. Here’s a high-level approach:

Open the certificate store
Search for the certificate with the specified subject name (“PS Cloud Authentication, O=APISafe, OU=Development, C=Canada”).
Retrieve the certificate and store it in a variable.
Use the certificate for authentication.



Then make a secure connection to the rest API endpoint
$baseUrl = https://APISafe/api/public/v3/;


#The Application API Key generated in APISafeInsight
$apiKey = "This is where the API key will be once it is given to you.";


#Username of APISafeInsight user granted permission to the API Key
$runAsUser = "TESTAPI";


$clientCertificateType = "BICertificate";