Credentials: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) K |
Admin (Diskussion | Beiträge) |
||
Zeile 10: | Zeile 10: | ||
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$SecurePassword | $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$SecurePassword | ||
</source> | </source> | ||
+ | |||
+ | |||
+ | Now you can use the variable ''$Credentials'' in the parameter ''-Credential''. For example: | ||
+ | <source lang="powershell"> | ||
+ | Invoke-Command -ComputerName <hostname> -Credential $Credentials -ScriptBlock { | ||
+ | Invoke-Expression $using:LogmanCMDStop | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | |||
+ | |||
Version vom 26. Januar 2018, 10:06 Uhr
Store password in a script (no Plaintext)
IMPORTANT: It only works if it is created on the same server as it is running.
$Username = '<username>' $Password = '<password>' $SecurePassword = ConvertTo-SecureString -AsPlainText $Password -Force $Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$SecurePassword
Now you can use the variable $Credentials in the parameter -Credential. For example:
Invoke-Command -ComputerName <hostname> -Credential $Credentials -ScriptBlock { Invoke-Expression $using:LogmanCMDStop }