Can I reduce the code for Powershell workflow

Can I reduce the code for Powershell workflow?

----------CODE-----------

workflow media {

Suspend-Workflow
Checkpoint-Workflow

1-Instanse

Get-ChildItem c:\windows -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:\test\media1.csv”

2-Instanse

Get-ChildItem c:\windows\media -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:\test\media2.csv”

3-Instanse

Get-ChildItem c:\ -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:\test\media3.csv”

4-Instanse

Get-ChildItem d:\ -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:\test\media4.csv”

5-Instanse

Get-ChildItem e:\ -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:\test\media5.csv”

6-Instanse

Get-ChildItem f:\ -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:\test\media6.csv”

7-Instanse

Get-ChildItem d:\test -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:\test\media7.csv”

8-Instanse

Get-ChildItem H:\test -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:\test\media8.csv”

}

Yes, the -Path parameter of Get-ChildItem can accept a comma-delimited list of paths.

Get-ChildItem -Path c:\one,c:\two,c:\three

Thanks but I need separate CSV for per path.

You “can” iterate through that list of paths and create the CSV in a separate CSV File(in it’s own directory) by using Foreach loops.

Something like this is a bit easier to read (and quite a bit shorter, due to the use of a loop.)

$reports = @{
    'c:\test\media1.csv' = 'c:\windows'
    'c:\test\media2.csv' = 'c:\windows\media'
    'c:\test\media3.csv' = 'c:\'
    'c:\test\media4.csv' = 'd:\'
    'c:\test\media5.csv' = 'e:\'
    'c:\test\media6.csv' = 'f:\'
    'c:\test\media7.csv' = 'd:\test'
    'c:\test\media8.csv' = 'h:\test'
}

$extensions = '*.avi', '*.m4a', '*.m4p', '*.m4v', '*.mobi', '*.mov', '*.doc', '*.mp3', '*.mp4', '*.mpeg', '*.mpg', '*.VOB', '*.wav', '*.wma', '*.wmv' 

foreach ($entry in $reports.GetEnumerator())
{
    Get-ChildItem -Path $entry.Value -Include $extensions -Recurse |
    Select-Object Directory, FullName, CreationTime, Length |
    Export-Csv -Path $entry.Key
}

[quote=11382]Something like this is a bit easier to read (and quite a bit shorter, due to the use of a loop.)
<P></P>

$reports = @{
‘c:\test\media1.csv’ = ‘c:\windows’
‘c:\test\media2.csv’ = ‘c:\windows\media’
‘c:\test\media3.csv’ = ‘c:’
‘c:\test\media4.csv’ = ‘d:’
‘c:\test\media5.csv’ = ‘e:’
‘c:\test\media6.csv’ = ‘f:’
‘c:\test\media7.csv’ = ‘d:\test’
‘c:\test\media8.csv’ = ‘h:\test’
}

$extensions = ‘.avi’, '.m4a’, ‘.m4p’, '.m4v’, ‘.mobi’, '.mov’, ‘.doc’, '.mp3’, ‘.mp4’, '.mpeg’, ‘.mpg’, '.VOB’, ‘.wav’, '.wma’, ‘*.wmv’

foreach ($entry in $reports.GetEnumerator())
{
Get-ChildItem -Path $entry.Value -Include $extensions -Recurse |
Select-Object Directory, FullName, CreationTime, Length |
Export-Csv -Path $entry.Key
}

[/quote]

I went in a different direction using an input file containing the folder to be scanned and the destination folder.

My input file located in c:\inputfiles consisting of:

c:\windows,d:\test\media1.csv
c:\windows\media,d:\test2\media2.csv

$include=@("*.mp3","*.wav")
foreach ($i in get-content "c:\inputfiles\tstinput.txt") {
gci($i -split ',')[0] -include $include -rec | select name | export-csv -path ($i -split ',')[1]
}