saving console output to text file Fails

This topic contains 8 replies, has 5 voices, and was last updated by  Mahin 1 year ago.

  • Author
  • #72646


    Hi folks. I'm trying to save the console output of the script from this Technet link, to a text file but it does not seem to work.

    I'm going thru and piping multiple addresses into the parameters and it simply does not save the output to a text file. This is what i've tried thus far using Out-File command below. The console screen output in ISE is perfect, but for some reason nothing gets saved to text file via Out-File cmdlet. Please help. Thanks a bunch

    foreach ($ADobject in $ADuserlist) {.\Find-DuplicateValues.ps1 -credential $mycredentials -address $ADobject -includeExchange -IncludeSIP | out-file "C:\temp\UPNduplicates.txt"}

  • #72683

    Matt Bloomfield

    Try adding -append -noclobber parameters to Out-File. That will ensure the file is appended to and not overwritten each time the loop runs.

    • #72691


      Hi Matt, I forgot to add in my question that I already tried "-Append" and it still does not output anything to the text file (empty, 0kb file). I even tried just one user query (code below) and it too did not output to file which perplexes me quite a bit. Thank you

      .\Find-DuplicateValues.ps1 -credential $mycredentials -address "" -includeExchange -IncludeSIP | out-file "C:\temp\UPNduplicates.txt"

  • #72713

    random commandline
    # Put results in variable
    $result = 
    foreach ($ADobject in $ADuserlist) {
        .\Find-DuplicateValues.ps1 -credential $mycredentials -address $ADobject `
        -includeExchange -IncludeSIP}
    # Pipe results to csv or text
    $result  | Export-Csv "C:\temp\UPNduplicates.csv" -NoTypeInformation
    # $result  | Out-File "C:\temp\UPNduplicates.txt" 
    • #72730


      random commandline,

      Thank you for your input. I tried using your $result variable and that too unfortunately did not work, nothing was output to the text file. I executed the $result variable and also saw that it too did not contain any data stored within it. I'm quite puzzled by this.

    • #72737

      Olaf Soyk

      Just to be completely sure ... does this work?

      'just some output' | Out-File "C:\temp\UPNduplicates.txt"
    • #72739


      Yup Olaf, "just some output" does work successfully (i output lots of stuff to C:\temp). If you open up the script, and you see that it has "Out-String" after the Get-ADobject cmdlet on lines 174 and 182. Not sure if that is causing the issue for it not to be able to save to file. I also tried " | tee -filepath "c:\temp\UPNduplicates.txt" " and that did not work either. Thanks

  • #72755

    Colin Nichols


    I did a little debugging on the Find-DuplicateValues.ps1 script and was able to reproduce the same results you had where the 0kb file was generated but not populated. I believe it has something to do with the FormatColor function being called after Out-String. I commented out everything after Out-String on 174, 182, 209, and 213. After doing that the text file populated with output.

    Hope that helps!

    • #72772


      Thank you Colin! That did the trick. Problem resolved, output recorded!

You must be logged in to reply to this topic.