Hi,
You cannot get the powershell variables in batch but you can get the output of powershell.
$securepw = convertto-securestring -string "hello" -asplaintext -force
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securepw)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
The batch file
FOR /F "DELIMS=" %%G IN ('powershell.exe -ExecutionPolicy Bypass -File C:\temp\pw.ps1') DO SET "pw=%%G"
https://stackoverflow.com/questions/23618016/use-powershell-variable-in-batch
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.