CodexBloom - Programming Q&A Platform

PowerShell 7.3 - Difficulty Passing a SecureString to a Remote Session Using New-PSSession

👀 Views: 59 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-16
powershell remoting securestring PowerShell

I'm testing a new approach and I'm having trouble with I'm converting an old project and I'm trying to implement I'm sure I'm missing something obvious here, but I'm trying to initiate a remote PowerShell session to a server using `New-PSSession`, but I'm having trouble passing a password securely..... I have a `SecureString` object that I created, but when I attempt to use it in the `New-PSSession` command, I get an behavior stating that the parameter is not valid. Here is what I have so far: ```powershell $securePassword = ConvertTo-SecureString 'myPlainTextPassword' -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential('myUsername', $securePassword) $session = New-PSSession -ComputerName 'remoteServer' -Credential $cred ``` When I run the above code, I receive the behavior: ``` New-PSSession : The specified credential is not valid. ``` I've already verified that the username and password are correct, and I can log in manually using the same credentials. I also tried using `Get-Credential`, but it didn't seem to make a difference. Additionally, I've checked if the remote server allows WinRM connections, and it does. Is there a specific way to ensure that the `SecureString` is correctly passed to the `New-PSSession` command? Any advice on how to troubleshoot this scenario would be appreciated, especially if there's a format or parameter I might be missing. I'm working on a CLI tool that needs to handle this. Is there a better approach? I recently upgraded to Powershell LTS. Any ideas how to fix this? The stack includes Powershell and several other technologies. I'm working in a Linux environment. Am I approaching this the right way?