title: Starting .ps1 Script from PowerShell with Parameters and Credentials and getting output using variable
body: <p>Hello Stack Community :) </p>
  
  <p>I have a simple goal. I'd like to start some PowerShell Script from an another Powershell Script, but there are 3 conditions: </p>
  
  <ol>
  <li>I have to pass credentials (the execution connects to a database that has specific user)</li>
  <li>It has to take some Parameters</li>
  <li>I'd like to pass the output into a variable</li>
  </ol>
  
  <p>There is a similar question <a href="https://stackoverflow.com/questions/60885735/starting-ps1-script-from-powershell-with-parameters-and-credentials-and-getting">Link</a>. But the answer is to use files as a way to communicate between 2 PS Scripts. I just would like to avoid access conflicts. @Update: The Main Script is going to start few other scripts. so the solution with files can be tricky, if the execution will be performed from multiple user at the same time.  </p>
  
  <p><strong>Script1.ps1</strong> is the script that should have string as an output. (Just to be clear, it's a fictive script, the real one has 150 Rows, so I just wanted to make an example)</p>
  
  <pre><code>param(  
  [String]$DeviceName
  )
  #Some code that needs special credentials
  $a = "Device is: " + $DeviceName
  $a
  </code></pre>
  
  <p><strong>ExecuteScripts.ps1</strong> should invoke that one with those 3 conditions mentioned above</p>
  
  <p>I tried multiple solutions. This one for examplte:</p>
  
  <pre><code>$arguments = "C:\..\script1.ps1" + " -ClientName" + $DeviceName
  $output = Start-Process powershell -ArgumentList $arguments -Credential $credentials
  $output 
  </code></pre>
  
  <p>I don't get any output from that and I can't just call the script with</p>
  
  <pre><code>&amp;C:\..\script1.ps1 -ClientName PCPC
  </code></pre>
  
  <p>Because I can't pass <code>-Credential</code> parameter to it..</p>
  
  <p>Thank you in Advance! </p>