title: Run "Invoke-Expression" statement as another user
body: <p>I have a PowerShell script/function, that takes few arguments and runs it.</p>
  
  <pre><code>Invoke-Expression ".\ScriptFile.ps1 $($Node.Name).xml C:\TempFolder\ $($Node.Name) local"
  </code></pre>
  
  <p>Now I want to run that as another user.</p>
  
  <p><code>Invoke-Expression</code> doesn't have an inherent parameter <code>credential</code> that facilitates this. On the other hand <code>Invoke-Command</code> has a <code>Credential</code> (<code>Get-Credential</code>) parameter that facilitates running as another user. I tried replacing <code>Invoke-Expression</code> with <code>Invoke-Command</code> with no luck.</p>
  
  <p>How do I tackle this to run the above expression as another user?</p>
  
  <p>Structure of Script Resource. </p>
  
  <pre><code>Script Deploy
          {       
              SetScript =     
  @"             
                  Set-Location D:\Deploy
                  Invoke-Expression ".\ScriptFile.ps1 $($Node.Name).xml C:\TempFolder\ $($Node.Name) local"                                               
  "@
  
              TestScript = 
              {
                  return $false            
              }
              GetScript = {
                  return @{   
                          GetScript = $GetScript
                          SetScript = $SetScript
                          TestScript = $TestScript
                      }
              }
              DependsOn = "[File]CopyMe"
          }
  </code></pre>
  
  <p>P.S.: All this happens inside a SetScript of <code>Script</code> User in Desired State Configuration.</p>