title: How can I get a output from a powershell function into a output file for example txt?
body: <p>I have made a create function in windows powershell: </p>
  
  <pre><code>function create(){
  param(
  $searchBase = "OU=Customers,DC=test,DC=nl",
  $NewOUs = @(Import-csv -Path $txt_csv.Text -Delimiter ";"),
  [switch]$ProtectOU
  )
  
  $Protect = $true
  If ($ProtectOU){$Protect = $true}
  
  &lt;# ------- CREATE OU ------- #&gt;
  foreach ($NewOU in $NewOUs) {
      try {
          New-ADOrganizationalUnit -Name $NewOU.company -Description $NewOU.description -Path $searchBase -ProtectedFromAccidentalDeletion $Protect
          }
      catch {
          Write-Host "OU already exists"
          }
  }
  
  $UserList = Import-Csv -Path $txt_csv.Text -Delimiter ";"
  
  &lt;# ------- CREATE USERS ------- #&gt;
  foreach ($User in $UserList) {
  
      $OU = $User.path
      $UPN = $User.UPN
      $Password = $User.password 
      $Detailedname = $User.firstname + " " + $User.Lastname 
      $UserFirstname = $User.Firstname 
      $FirstLetterFirstname = $UserFirstname.substring(0,1) 
      $SAM =  $User.UPN
      $Company = $User.company
      $Description = $User.description
      $AccountExpirationDate = $User.accountexpirationdate
  
      $params = @{ 'Name'=$Detailedname;
                   'SamAccountName'=$SAM;
                   'UserPrincipalName'=$UPN+'@test.nl';
                   'DisplayName'=$Detailedname;
                   'GivenName'=$UserFirstname;
                   'Surname'=$User.Lastname;
                   'AccountPassword'=(ConvertTo-SecureString $Password -AsPlainText -Force);
                   'Enabled'=$True;
                   'PasswordNeverExpires'=$True;
                   'Path'=$OU;
                   'Company'=$Company;
                   'Description'=$Description;
                   'AccountExpirationDate'=$AccountExpirationDate
                   'HomeDrive' = "H:"
                   'HomeDirectory' = "\\home\userdata$\$SAM"
                   'ProfilePath'="\\dc-test\User Profiles$\$SAM"                 
                  }
  
      New-ADUser @params
  }
  </code></pre>
  
  <p>I want this create function as a output file for example in a txt. </p>
  
  <p>This is my wpf button object:</p>
  
  <pre><code>$button_add.Add_Click({create})
  </code></pre>
  
  <p>When I click on the button the output must generated a output file. I already tried a lot of solutions such ass:</p>
  
  <p>Create | out-file but I don't get the information I want:</p>
  
  <p>source: <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/out-file" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/out-file</a></p>
  
  <p>Is it possible to do this?</p>
  
  <p>Kind regards</p>