I need to modify the command file startup for a site written in Micro Focus COBOL to access an Azure key vault. I wrote a PowerShell script to access the key vault – I need to pass back to the command file data which the command file uses to set environmant variables. I don’t want to pass a variable at the Machine level – that will defeat the purpose of using a key vault. How do I send a string variable back to the command file?
I tried to set an environment variable in PowerShell that was non-transitory at the Process level – hoping it would be recognized by the Windows command file that called it. The varaible was not recognized after coming back from PowerShell.
the startup command file
ECHO SETTING ENVIRONMENT SPECIFIC VARIABLES
SET REGION_NAME=theRegion
powershell.exe -File "C:UtilCallAzure.Ps1"
SET FIRST_ENV_VAR=DSN=DataSet;UID=UserID;PWD=%FromPowerShell%
...
SET SHAREDFILE_LOCATION=\theServertheFolder
ECHO DONE SETTING ENVIRONMENT SPECIFIC VARIABLES
the powershell script
ECHO 'SETTING ENVIRONMENT SPECIFIC VARIABLES - PowerShell'
$Url = "https://lookupdv.site.org/API.KeyVault"
$JSON = "application/json"
$Body = @{
URI = "KeyName"
secretname = "UserID"
}
$Password = Invoke-RestMethod -Method 'Post' -Uri $url -ContentType $JSON -Body ($body | ConvertTo-Json)
[System.Environment]::SetEnvironmentVariable('FromPowerShell', $Password, [System.EnvironmentVariableTarget]::Process)
ECHO 'DONE SETTING ENVIRONMENT SPECIFIC VARIABLES - PowerShell'
this doesn’t work
should I change the Set command to target User instead of Process?