Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Get-ChildItem -Path .\Generated | #Get each file in the folder
- ForEach-Object { #Creates a loop to apply to each file in folder found by Get-ChildItem
- $inputFile = $_.Name #Establish variable for the next line
- $outputFile = $inputFile -replace '.*2018-', 'Filtered_' -replace '.........\.csv', '.csv' #rename file
- Import-Csv $_.FullName | #Import CSV file by filename
- Select * -ExcludeProperty "Size on Disk", "Size", "Owner" | #Only select wanted columns
- Where-Object{$_.Filename -notlike "{*}{*}"} | #Remove filename junk
- Where-Object{$_.Filename -notlike "VM_*"} | #Remove filename junk - voicemails
- Where-Object{$_.Filename -notlike "*.tmp"} | #Remove filename junk - temp files
- Where-Object{$_.Filename -notlike "*.css"} | #Remove filename junk - css files
- Where-Object{$_.Filename -notlike "*.gif"} | #Remove filename junk - gif files
- Where-Object{$_.Filename -notlike "*.download"} | #Remove filename junk - download files
- Where-Object{$_.Filename -notlike "*.ini"} | #Remove filename junk - .ini files
- Where-Object{$_.Folder -notlike "*\AppData\*"} | #Remove folder junk - AppData
- Where-Object{$_.Folder -notlike "*\IntelGraphicsProfiles"} | #Remove folder junk - IntelGraphicsProfiles
- Where-Object{$_.Folder -notlike "*\xTools\*"} | #Remove folder junk - xTools
- Where-Object{$_.Folder -notlike "*RECYCLE.BIN*"} | #Remove folder junk - Recycling Bin
- Export-Csv .\Filtered\$outputFile -NoTypeInformation #Output to a new CSV file
- # Write-Host $outputFile #Used for testing output
- } #close foreach-object loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement