Quantcast
Viewing latest article 23
Browse Latest Browse All 120

Invoke-Command with -credentials

I want to invoke a command on a remote server, I do not want to have to put in the password to run the script. I've tried encrypting the password and storing it in a txt file.

 $username = "Mydomain\service.account" $password = cat C:\username-password-encrypted.txt | convertto-securestring $cred = new-object -typename System.Management.Automation.PSCredential - argumentlist $username, $password Invoke-command $cred -Computer myserver -scriptblock {param([string]$LocalUser); Add-PSSnapin Citrix* ; Get-BrokerSession -max 10000 | Where-Object brokeringusername -eq  "mydomain\$($LocalUser)" | Stop-BrokerSession} -ArgumentList $user

Here is the error I get

 Invoke-Command : A positional parameter cannot be found that accepts argument 'System.Management.Automation.PSCredential'. At \\uncpath\citrix\Installation Media\Citrix\Ticketing_script\Ticketing_Script - Copy (3).ps1:70 char:1+ Invoke-command $cred -Computer MyServer -scriptblock {param([s ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : InvalidArgument: (:) [Invoke-Command],   ParameterBindingException+ FullyQualifiedErrorId :   PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand

There has to be an easier way to run this command on myserver without having to put in the password every time.


Viewing latest article 23
Browse Latest Browse All 120

Trending Articles