title: WIndows Form textbox pass text value to a Powershell Runscript
body: <p>I am developing a <strong>Win form</strong> with C# to create a tool that would run several PowerShell scripts within a <strong>PowerShell Run space</strong> and show the results on a text file. </p>
  
  <p>Right now I have the following.</p>
  
  <p>... a Win-form with a button that will return the results of the PowerShell script below:</p>
  
  <pre><code> txtUserInfo.Text = RunScript(@"Get-ADUser UserNameGoesHere -Properties * | Select-Object Enabled, @{Expression={$_.LockedOut};Label='Locked';}, DisplayName, GivenName, SurName, Mail, @{ Expression ={[DateTime]::FromFileTime($_.LastLogon)}; Label='Last Logon';}, @{Expression={$_.Created};Label='Date Created';}, passwordlastset, Passwordneverexpires | Format-list");
  </code></pre>
  
  <p>The script is working and is showing the results on a textbox.</p>
  
  <p><a href="https://i.stack.imgur.com/6DLA8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6DLA8.png" alt="enter image description here"></a></p>
  
  <p>This works with the Users name hard coded into the PowerShell  Script:</p>
  
  <blockquote>
    <p>RunScript(@"Get-ADUser <strong>UserNameGoesHere</strong> -Properties * |</p>
  </blockquote>
  
  <p>I am trying to find a way to use a Textbox for input on the Win form and pass that value to the PowerShell Run space as a variable. But I have not been able to find anything posted that will assist me.</p>
  
  <p>Any pointers are appreciated</p>
  
  <p>Regards,</p>