Windows PowerShell Gives Password in Enter-PSSession Command

I am writing a project where I run a PowerShell script and create a new PSSession as follows:

PowerShell.exe -Command enter-pssession myUser -credential userName

When I run this, it opens a dialog box prompting the user to enter a password. However, I would prefer that the user can enter the password along with the rest of the above line, instead of worrying about the invitation. I am very new to PowerShell, and everything I found in the docs provides only ways to enter password hints. Is this something that can be done in PowerShell? Thank!

+4
source share
2 answers

Yes, you can specify a password when opening new-pssession, as shown below

$passwd = convertto-securestring -AsPlainText -Force -String <your password>

$cred = new-object -typename System.Management.Automation.PSCredential 
-argumentlist "Domain\User",$passwd

$session = new-pssession -computername <computer> -credential $cred
+6

Rahul , , . , , .

:

 Get-Credential | Export-Clixml "mycredentials.xml"

:

$cred = Import-Clixml "mycredentials.xml"
new-pssession -computername <computer> -credential $cred

:

new-pssession -computername <computer> -credential (Import-Clixml "mycredentials.xml")

, , .

+8

Source: https://habr.com/ru/post/1534271/


All Articles