pratikdarak21
Feb 13, 2024Brass Contributor
Issue with Write-Host while using Get-Secret in PowerShell Version 5.1.14409.2001
Hi Team,
I have below lines of code in PowerShell script. While running the script in there is no message getting output for Write-Host for PS version 5.1.14409.2001. But, script is working fine for 5.1.22000.2713.
Could you please help me out how to solve the Write-Host issue ?
-- Code --
$startDateTime = Get-Date;
$invocationPath = Get-Location;
$logFilePath = "{0}\Log\{1}_{2}_{3}.log" -f $invocationPath, "GetSecretTest",$env:COMPUTERNAME, $startDateTime.ToString("ddMMyyHHmm");
if(Test-Path $logFilePath) { Remove-Item -Path $logFilePath -Confirm:$false; }
Start-Transcript -Path $logFilePath;
Write-Host "Get Password Start";
$Secret = Get-Secret -Name TestSecret -AsPlainText
Write-Host $Secret
Write-Host "Get Password End";
Stop-Transcript;
- To solve the above issue, I have changed position of one line of code starting with "Get-Secret" above the Start-Transcript. This is workaround I have used for PS 5.1.14409.2001.