Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, October 26, 2016 2:19 AM
Hello Experts,
I need help with powershell Invoke command with get credential. I am writing a script to open application on remote computer using invoke-command. I have installed WinRM on remote server and it's using listening port as 5985.
The script is running fine but the userid/password prompt keep popping up even after giving the credentials in the script too and I want to disable that. I have read a lot of forums but none of them worked for me. Below is some of my code.
$Username = 'labuser'
$Password = 'labuser'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Invoke-command -ScriptBlock {"D:\abc\C123.exe.exe"} -Credential (get-credential) $credential -Verbose -ComputerName abc.com
Any help will be apprecieted.
Thanks
Manish
Msharma
All replies (2)
Wednesday, October 26, 2016 6:47 AM ✅Answered
Hi Manish,
as jrv said, you need to actually use the variable you store the credential in:
# Old line
Invoke-command -ScriptBlock {"D:\abc\C123.exe.exe"} -Credential (get-credential) $credential -Verbose -ComputerName abc.com
# New line
Invoke-command -ScriptBlock {"D:\abc\C123.exe.exe"} -Credential $cred -Verbose -ComputerName abc.com
Cheers,
Fred
There's no place like 127.0.0.1
Wednesday, October 26, 2016 2:43 AM
You create "$cred" but you never use it.
\(ツ)_/