Unable to connect to Remote Server when we pass credentials as secure string but able to login when we are manually entering the password instead of converting into string.
The script i am using as below
param( [string]$ServiceAccount = 'xyz/v-abc', [string]$ServiceAccountPassword = '$Kxyz')$pwdSecureString = $password | ConvertTo-SecureString -AsPlainText -force$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServiceAccount, $pwdSecureString$appServer = 'xyz'Invoke-Command -ComputerName $appServer -ScriptBlock { Get-service -Name 'WinRM'} -Credential $cred
#The error i am facing is below
[xyz] Connecting to remote server xyz failed with the following error message : The username or password is incorrect. For more information, see the about_Remote_Troubleshooting Help topic.+ CategoryInfo : OpenError: (xyz) [], PSRemotingTransportException+ FullyQualifiedErrorId : LogonFailure,PSSessionStateBroke
#I am able to connect to server when i use below command i.e., entering the password while script execution instead of passing the password as $cred
Invoke-Command -ComputerName $appServer -ScriptBlock { Get-service -Name 'WinRM'} -Credential xyz
Can you please help us in connecting the remote server using invoke-command by passing the password as securedstring