I'm working on a Powershell Script which reads an ssh keys and known hosts from a file and writes that to another file.
I read the key with
$SshPrivateKey = Get-Content 'ssh-keys\id_rsa'
Then I write the newfile with
New-Item -path $SshKeysDir -Name $SshPrivateKeyFile -Value $SshPrivateKey -ItemType file -force
This works fine with the public key. But for some strange reason it does not work with the private key. The new file ends up with just
System.Object[]
As a workaround I'm currently using
$SshPrivateKey > $testpath
which writes the file correctly. Also writing the content to the console renders the expected private key
Write-Output $SshPrivateKey
What bothers me most is the fact that it works for other files such as the public key or the known host. Just not for the private key file. The working command for the public key looks like this
New-Item -path $SshKeysDir -Name $SshPublicKeyFile -Value $SshPublicKey -ItemType file -force
One difference I see is that the public key is multiline vs. single line in case of the public key.
Can anyone point shed some light on this mistery?