I am executing the ssh-keyscan command in a PowerShell script to update the SSH known hosts file on my Windows system.
Environment details:
PowerShell:5.1.18362.752
Operating system: Windows 10 x64 1903(OSBuild 18362.1082)
Language: English
My code is as follows:
Start-Transcript -Path C:\Windows\temp\abc.log
$sshKnownHostFile = "$Env:USERPROFILE\.ssh\known_hosts"
$cmd = "ssh-keyscan -p 7000 blah.net | Out-File -Encoding ASCII $sshKnownHostFile -Append"
Invoke-Expression $cmd -Verbose
Stop-Transcript
The problem I am experiencing is that, no matter what I try, the console output of ssh-keyscan is not captured in the transcript file. All that's captured in the transcript file is the following:
**********************
Windows PowerShell transcript start
Start time: 20201008201659
Username: DESKTOP-NIFKPBT\kiranh
RunAs User: DESKTOP-NIFKPBT\kiranh
Configuration Name:
Machine: DESKTOP-NIFKPBT (Microsoft Windows NT 10.0.18362.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 1280
PSVersion: 5.1.18362.752
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.752
BuildVersion: 10.0.18362.752
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Windows\temp\abc.log
**********************
Windows PowerShell transcript end
End time: 20201008201707
**********************
I have attempted the following to resolve the issue:
Invoke-Expression $cmd -Verbose | Out-Default
This was as per the suggestion at: https://github.com/PowerShell/PowerShell/issues/10994#issuecomment-550528523Invoke-Expression $cmd -Verbose | Out-Host
This was the suggestion at: https://github.com/PowerShell/PowerShell/issues/10994#issuecomment-596132121[System.Environment]::SetEnvironmentVariable("GIT_REDIRECT_STDERR", "2>&1", "User")
This was as per this response. The above answer was for Git. Since ssh-keyscan.exe is from the Git family of utilities, I tried using the same to see if my issue would be resolved.Use of
Start-Process
cmdlet to invoke ssh-keyscan.exeDirectly invoking ssh-keyscan.exe in the PowerShell script, just like an external program is executed on the command prompt.
None of the above have really helped. The output captured in the transcript log is the same in all of the above cases.
How can I get this working?