title: PowerShell script to get logged in user
body: <p>I am looking to run a script on a remote machine using an automation tool that runs the scripts in the system context. </p>
  
  <p>What I have so far:</p>
  
  <pre><code>$userId = Get-Process -IncludeUserName explorer | % username | sort Username -Unique
  Write-Host $userid.ToLower()
  </code></pre>
  
  <p>Results:</p>
  
  <pre>
  Get-Process : A parameter cannot be found that matches parameter name
  'IncludeUserName'.
  At line:1 char:39
  + $userId = Get-Process -IncludeUserName &lt;&lt;&lt;&lt;  explorer | % username | sort Username -Unique
      + CategoryInfo          : InvalidArgument: (:) [Get-Process], ParameterBindingException
      + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand
  
  ToLower : You cannot call a method on a null-valued expression.
  At line:2 char:27
  + Write-Host $userid.ToLower &lt;&lt;&lt;&lt; ()
      + CategoryInfo          : InvalidOperation: (ToLower:String) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
  </pre>
  
  <p>Any ideas how to help this script? Or the cause of the errors?</p>