Skip to content

Instantly share code, notes, and snippets.

@Na0mir
Last active August 29, 2015 14:18
Show Gist options
  • Save Na0mir/62d6aefacbfefb2d2bc4 to your computer and use it in GitHub Desktop.
Save Na0mir/62d6aefacbfefb2d2bc4 to your computer and use it in GitHub Desktop.
Export local file's property to CSV file.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 22.03.2013
# Description: Export local file's property to CSV file.
# ----------------------------------------------
# -- Options -- #
$LocalPath = "files"
$logfile = "output-filename.csv"
$count = 0
$begindate = Get-date
$logfileexist = Test-path $logfile
# -- Script -- #
if ($logfileexist -eq "True"){ remove-item -path $logfile -Confirm:$false }
write-output "FileName" | out-file -filepath $logfile -append
try
{
## Get all items into the folder
$localFolder = Get-ChildItem $LocalPath
$count_item = $localFolder.Count
## Foreach items in the folder, export the name
$localFolder | ForEach-Object {
## Change 'Name' by the property of your choice
$filename = $_.Name
write-output "$filename" | out-file -filepath $logfile -append
$count++
$a = ($count / $count_item)
$b = "{0:P2}" -f $a
Write-Progress -activity "Export filename items from '$LocalPath' folder..." -status "Progress: $b"
}
Write-Progress "done" "done" -completed
## Display summary informations about eh export job
$enddate = Get-date
$datediff = (($enddate - $begindate)).ToString()
write-host ""
write-host "$count filename exported in $datediff min." -ForegroundColor Green
write-host ""
write-host "----------------------------------"
write-host ""
## Display availables properties if someone want to export more
write-host "Properties availables:"
Get-ChildItem $LocalPath | Get-Member -MemberType Property
}
catch
{
write-host "The script has stopped because there has been an error: "$_ -foregroundcolor Red
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment