Jul 03 2017 02:00 AM
I have a powershell script that loops a fileshare and reports the properties of all the files.
This part reports to a .txt file:
Get-ChildItem -Recurse $source | ?{-not $_.PSIsContainer} | ForEach-Object {Audit-File $_} | Sort-Object fullname | Select FullName,CreationTime,LastWriteTime,Length,Owner | Out-File C:\filename.txt
The output is something like this:
FullName : C:\temp\testfile CreationTime : 30-6-2017 13:34:16 LastWriteTime : 8-9-2014 17:15:57 Length : 5752832 Owner : BLA\bla.bla Author :
But I would like to have something like this:
FullName,C:\temp\testfile,CreationTime,30-6-2017 13:34:16,LastWriteTime,8-9-2014 17:15:57,Length,5752832,Owner,BLA\bla.bla,Author
So one line for each record.
I cannot use a .csv as this cannot handle things like "é", etc.
Jul 03 2017 02:53 AM
Use the -Encoding parameter with Export-CSV, it works just fine. For example:
Export-Csv -NTI blabla.csv -Encoding Unicode
Jul 03 2017 03:04 AM
If I do so, my text will be changed.
For example "énter" will be changed to "?nter". Has something to do with utf encoding.
Jul 03 2017 03:59 AM
You can change the encoding to UTF8 or other, as necessary. Unicode works just fine with énter for example.
Jul 03 2017 04:03 AM
SolutionTry this script for output with txt file
$Details=Get-ChildItem -Recurse $source | ?{-not $_.PSIsContainer} | ForEach-Object {Audit-File $_} | Sort-Object fullname | Select FullName,CreationTime,LastWriteTime,Length,Owner $Outputs =@() ForEach($Detail in $Details) { $Output = "Fullname,"+$Detail.FullName+",CreationTime,"+$Detail.CreationTime+",LastWriteTime ,"+ $Detail.LastWriteTime+",Length ,"+"$Detail.Length"+ ",Owner,"+$Detail.Owner $Outputs +=$Output } $Outputs | Out-File C:\filename.txt
Jul 03 2017 04:03 AM
SolutionTry this script for output with txt file
$Details=Get-ChildItem -Recurse $source | ?{-not $_.PSIsContainer} | ForEach-Object {Audit-File $_} | Sort-Object fullname | Select FullName,CreationTime,LastWriteTime,Length,Owner $Outputs =@() ForEach($Detail in $Details) { $Output = "Fullname,"+$Detail.FullName+",CreationTime,"+$Detail.CreationTime+",LastWriteTime ,"+ $Detail.LastWriteTime+",Length ,"+"$Detail.Length"+ ",Owner,"+$Detail.Owner $Outputs +=$Output } $Outputs | Out-File C:\filename.txt