0

My goal is as follows: I need to be able to go in to one of our servers and run a script but I have to do this remotely through PowerShell. It needs to run silently - not require any user input. There is a username\password that I want to provide for the script along with an IP address.

I need to be able to RDC so that I can edit files on the server after a task has completed on Octopus.

Everything I have tried so far has required a password upon opening. Could someone point me in the right direction?

Right now I have this: New-PSSession -ComputerName 100.100.10.100 -Credential Code1\name I'm aware that this will prompt for a password but was wondering if there was a way around this or if there is another type of command that I should be using.

9
  • What have you tried so far? I think that we will need more details. What command is prompting for a password? Commented May 2, 2018 at 13:49
  • 1
    Why RDC in when you could connect using PS Remoting and check the files with PowerShell? Commented May 2, 2018 at 13:56
  • Ben, it doesn't really matter whether or not I use PsRemoting or not. I have been trying to use a new PSSession but it still prompts me for the password which will be an issue with automation. Right now I have this: New-PSSession -ComputerName 100.100.10.100 -Credential Code1\name Commented May 2, 2018 at 14:07
  • 1
    Well, first of all you haven't really clrified what exactly is prompting for credentials. Second, if you have more information about your question you should edit the question to include the information not put it in a comment. Third. the command that you have shown does not pass the password to the New-PSSession cmdlet so yes you would be prompted. Look at the Get-Credential cmdlet. Commented May 2, 2018 at 14:26
  • Yes, there is a way around the credential prompt. Use Get-Credential to create a credential object including password that you pass to New-PSSession. Of course this generally involves putting the password into the script which is not the most secure thing in the world to do. Commented May 2, 2018 at 15:37

1 Answer 1

1

Create a credential object,

$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UserName,$Password
New-PSSession -Credential $Credential -computerName $computer

Get the $Username and $Password using Parameters, $Password will be of type [system.Security.SecureString

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.