Search code examples
powershellpowershell-remoting

Silently RDC with Powershell


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.


Solution

  • 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