0

I am trying to run a powershell script from a TeamCity Windows Slave to another server for deploying my application.

This is BuildConfig:

username = "<username>"
$password = "<password>"
$secstr = New-Object -TypeName System.Security.SecureString; 
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;
Invoke-Command -ComputerName "<computer_name>" -Credential $cred -FilePath "deploy.ps1"

I am getting the following error.

following error message : Logon failure: unknown user name or bad password. 
[13:57:52]  [Step 1/1] For more information, see the about_Remote_Troubleshooting Help topic.

I have used the correct User name and password only. I have also checked the Local User security policies. Am I missing something?

sriramsm04
  • 343
  • 1
  • 7
  • 22

1 Answers1

0

Is it just a paste error that missed the $ from username ? Does the user name and password work fine outside the script ? Are the variables being substituted in properly. Do the logs show ? I’ve never used that construct to make a pscredential before. Is this one mentioned here not working.

https://pscustomobject.github.io/powershell/howto/PowerShell-Create-Credential-Object/

  • I'm passing the Local Administrator credentials of the remote server. Will it work? – sriramsm04 May 23 '20 at 06:00
  • @sriramsm04 do they work to do that you’re trying to do outside the script ? If they don’t then that’s your first problem. Does the script work if you just hard code in and replace the user name and password to try it. What does the script write back to you if you pass in verbose – Gabriel McColl May 25 '20 at 08:56
  • So the issue was with the user being local Administrator, as it cannot be used for running commands remotely. I used my admin user and was able to achieve the same. – sriramsm04 May 27 '20 at 08:22