saving console output to text file Fails

Welcome Forums General PowerShell Q&A saving console output to text file Fails

This topic contains 8 replies, has 5 voices, and was last updated by

 
Participant
1 year, 9 months ago.

  • Author
    Posts
  • #72646

    Participant
    Points: 33
    Rank: Member

    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.

    https://gallery.technet.microsoft.com/scriptcenter/Find-Duplicate-Values-in-6b012059

    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

    Participant
    Points: 41
    Rank: Member

    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

      Participant
      Points: 33
      Rank: Member

      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 "john@company.com" -includeExchange -IncludeSIP | out-file "C:\temp\UPNduplicates.txt"

  • #72713

    Participant
    Points: 52
    Rank: Member
    # 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

      Participant
      Points: 33
      Rank: Member

      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

      Participant
      Points: 1,081
      Helping Hand
      Rank: Community Hero

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

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

      Participant
      Points: 33
      Rank: Member

      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

    Participant
    Points: 1
    Rank: Member

    Mahin,

    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

      Participant
      Points: 33
      Rank: Member

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

The topic ‘saving console output to text file Fails’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort