title: Invoke-Command with -credentials
body: <p>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. </p>
  
  <pre><code> $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
  </code></pre>
  
  <p>Here is the error I get </p>
  
  <pre><code> 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
  </code></pre>
  
  <p>There has to be an easier way to run this command on myserver without having to put in the password every time.</p>