Need help converting this powersheel in VBA code. I am new to VBA , please advise/guide.
Here is the Power Shell code that I need to convert in VBA code
#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";
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";
Here is the Power Shell code that I need to convert in VBA code
#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";