Author Posts

June 12, 2017 at 3:19 pm

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"}

June 12, 2017 at 9:01 pm

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

June 12, 2017 at 10:34 pm

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"

June 13, 2017 at 2:37 am

# 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" 

June 13, 2017 at 11:05 am

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.

June 13, 2017 at 11:17 am

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

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

June 13, 2017 at 11:40 am

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

June 13, 2017 at 2:47 pm

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!

June 13, 2017 at 4:02 pm

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