How to save credential for winrm?

Learn to remotely control a computer using powershell.

Connecting like this:
Enter-PSSession -ComputerName 10.15.29.8 -Credential $crd


Before this command can be a variable in the crd to maintain credential:
$crd = Get-Credential

But if I periodnow powershell, my variable $crdwill remain.

How to save credential to and after computer restart I can connect to a remote powershell without being prompted for a password? Immediately, I note that the computers in different domains.
April 3rd 20 at 17:38
2 answers
April 3rd 20 at 17:40
Solution
Understood!

So you don't have to enter each time the password, save it in encrypted form in the file:
$crd = Get-Credential
$crd.Password | ConvertFrom-SecureString | Set-Content pass.txt


Using the username and password from a file will create a Credential in a variable and using that variable to connect to the server:
$user = "domain\administrator"
$password = Get-Content pass.txt | ConvertTo-SecureString
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $password
Enter-PSSession -ComputerName 10.15.29.8 -Credential $cred
April 3rd 20 at 17:42
Try:
$Global:crd = Get-Credential
Did not help, well, I don't even need to variable, in a file, now here is a study:
https://windowsnotes.ru/powershell-2/soxranenie-uc... - Immanuel.Heller commented on April 3rd 20 at 17:45

Find more questions by tags PowerShellWindows