hl2guide

File List Creator 1.0A - PowerShell

Jul 30th, 2017
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Lists all files on a drive or drives
  2. # Version: 1.0A
  3. # Date Modified: 30/07/17
  4. # Author: hl2guide
  5.  
  6. # Sets a list of drive letters (seperated by *)
  7. $drivesstring = 'g*h*m*v*w*x*y'
  8. $drives = @($drivesstring.split('*'))
  9.  
  10. # Loops through drive list
  11. foreach ($drive in $drives)
  12. {
  13.  
  14.     # Sets Drive Letter
  15.     $driveLetter = $drive
  16.  
  17.     Write-Host
  18.     Write-Host 'Creating File List for the drive:' $drive
  19.  
  20.     # Gets the label of the disk
  21.     $VolumeName = [System.IO.DriveInfo]::getdrives() | Where-Object {$_.Name -eq "$driveLetter"+':\'} | Select-Object -Property VolumeLabel
  22.     $VolumeName = $VolumeName.VolumeLabel.ToString()
  23.  
  24.     # Gets the list of files on the disk
  25.     $data = Get-ChildItem -Path $driveLetter':\' -Recurse -File -Name | sort length –Descending
  26.  
  27.     # Outputs the list to a text file
  28.     $outputPath = $PSScriptRoot+"\all_files_on_$driveLetter-($VolumeName).txt"
  29.     Set-Content -Path $outputPath -Value $data
  30.  
  31.     Write-Host
  32.     Write-Host 'Target Folder was:' $PSScriptRoot
  33.     Write-Host 'Created File List at:' $outputPath
  34. }
Advertisement
Add Comment
Please, Sign In to add comment