Author Posts

November 9, 2013 at 12:47 am

folder= (Get-Content -Path C:\path.txt)
$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')

Get-ChildItem $folder -include *.avi,*.m4a,*.m4p,*.m4v,*.mobi,*.mov,*.doc,*.mp3,*.mp4,*.mpeg,*.mpg,*.VOB,*.wav,*.wma,*.wmv -Recurse |

select Directory,FullName,CreationTime,Length | Export-Csv -Path "c:\output\mediafiles_$CurrentDate.csv"

_____________________

path.txt is below

c:\

c:\wondows

c:\windows\media

Need a separate csv for each path.

November 9, 2013 at 2:55 am

You are using recurse but are specifying different sub folders in your input file. Only need one or the other not both. You could just make one big file which includes the path – then you could sort and filter on that. -Include won't work in the way you are using it
Why take directory and full name – you have redundant information. I'd take either fullname OR directory and Name

If you have to have different files per folder then do something like this

$folders = (Get-Content -Path C:\test2\path.txt)
$exts = ".txt", ".evt", ".jpg", ".png"

foreach ($folder in $folders) {
Get-ChildItem -Path $folder -File |
where Extension -in $exts |
select Directory, Fullname, CreationTime, Length |
Export-Csv -Path "$folder\files.csv" -NoTypeInformation
}

November 9, 2013 at 3:12 am

Thanks Richard. I am checking.

November 9, 2013 at 3:22 am

It is providing a single CSV not multiple.

November 9, 2013 at 3:49 am

Please post the code you are using and the contents of your path.txt file. I tested my code before posting it and it produces one csv per folder in that folder

November 9, 2013 at 4:21 am

Script.
workflow media {

Suspend-Workflow
Checkpoint-Workflow

$folders = (Get-Content -Path C:\path.txt)
$exts = “.txt”, “.evt”, “.jpg”, “.png”

foreach ($folder in $folders) {
Get-ChildItem -Path $folder -File |
where Extension -in $exts |
select Directory, Fullname, CreationTime, Length |
Export-Csv -Path “$folder\files.csv” -NoTypeInformation
}

}
path.txt
c:\
c:\windows
c:\windows\media

November 9, 2013 at 4:27 am

That code won't work in a work flow because work flows don't allow aliases or positional parameters. Try the code as I posted, in a normal script. Once that works for you I can show you how to make the workflow work. Also I don't understand the logic of immediately suspending the workflow

November 9, 2013 at 4:47 am

Awesome info Richard. Need resume & suspend during running that script. Please help.