top of page

You can use a PowerShell script to get a list of all of the files of particular type in a directory by using the -Include command. In this example, we use the get-childitem command, followed by the path with the source files, followed by the command to include only certain types of files.

get-childitem C:\FooFolder\excels\ -Include *.xls -Recurse

The -Recurse setting causes the script to account for files in subfolders.

If we run a script to set the result to equal a particular value:

$a = get-childitem C:\FooFolder\excels\ -Include *.xls -Recurse

We can use this to generate a count of the number of files that the script finds:

$a.Count


 
 

Here's a PowerShell script that you can use to get the MD5 hash values of multiple files that are in a directory with multiple levels of subfolders:

PS C:\Users\SeanKOShea> Get-FileHash -Algorithm MD5 -Path (Get-ChildItem "C:\FooFolder\baseball2\*.*" -Recurse -force) | export-csv c:\FooFolder\Batch01b.csv

The Get-FileHash algorithm can be set to generate MD5, SHA1 and other hash values. Follow this command with the folder containing your source files. This will work even if the files are saved in multiple subdirectories, thanks to the, 'Recurse -force'. Enter a pipe | and then use the export-csv command to output the results to a comma separated value file.

The .csv file that is generated will look like this:

This PowerShell script will work if you list different directories in multiple copies of this one line script, put them on separate lines in PowerShell, and run them all at once.


 
 

You can use a simple PowerShell script to extract specified columns from a .csv file.

Change the directory to the one containing your source .csv file. List the headings used in the .csv file - in this example, 'PlayerID'; 'GS'; 'TeamID' and 'YearID'.

Then list the paths to the source file and the file to be generated with the exported columns.

PS C:\foofolder\csv> $Headers = @( "PlayerID" "GS" "TeamID" "YearID" # Add all other desired headers here "$((Get-Date).ToShortDateString())" # << Header for todays date e.g. 19/06/2018 ) Import-Csv -Path "C:\Foofolder\csv\Fielding.csv" | Select $Headers | Export-Csv -Path "C:\Foofolder\csv\ExportFile.csv" -Force -NoTypeInformation

The script will then be customized and ready to run. It will out a new .csv file with only the columns you're interested in.

Thanks to Francis Hagyard for posting this here. You can repeat the script for multiple .csv files and run it all at once in PowerShell.

Unlike the method in command prompt in demonstrated in the Tip of the Night for April 24, 2020, the PowerShell script can extract data from columns beyond the 31st column in the .csv file.


 
 

Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page