search documents in powershell
if you want to do the easy way that only runs the next line in the powershell terminal
Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue
the advanced way is the next script that runs in powershell ise or a .ps1 file in the terminal
#works but isnt organizated
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue | Select -Expand Fullname
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue| Select-Object -Property Name,Space
#to get properties of a file
#Get-ItemProperty -Path C:\fso\a.txt | Format-list -Property * -Force
#Final
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue| Select-Object -Property Name,LastAccessTime,Length,Directory
#To Check
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue| Select-Object -Property Name,LastAccessTime,DisplayInBytes(Length),Directory
#Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine
#Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Function Format-FileSize() {
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {""}
}
$toSearch = "*.mp3"
$filenamedotcsv = c:\test.csv
#Get-ChildItem | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}
#Get-Childitem -Path C:\, D:\, I:\ -Include "*.mp3" -Recurse -ErrorAction SilentlyContinue | Select-Object -Property Directory,Name,LastAccessTime,@{Name="Size";Expression={Format-FileSize($_.Length)}}
#Get-ChildItem -Path E:\music -Filter *.mp3 -Recurse | Select-Object directoryname, basename, length | Export-Csv -Path c:\fso\music.csv -Encoding ascii -NoTypeInformation
Get-ChildItem-Path C:\, D:\, I:\ -Include $toSearch -Recurse -ErrorAction SilentlyContinue | Select-Object -Property Directory,Name,LastAccessTime,@{Name="Size";Expression={Format-FileSize($_.Length)}}| Export-Csv -Path $filenamedotcsv -Encoding ascii -NoTypeInformation
if dont work execute the next command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Comentarios
Publicar un comentario