简体   繁体   中英

Create .txt file inPowesShell containing Version number for all files in folder

Good afternoon,

Although I've been programming in VBA for 20 years, I'm on Week 2 with PowerShell, so please be patient!

I want to use a PowerShell script to create a txt file containing details for all .dll files greater than 15000 bytes within the specfied folder thus:

$MySourceFolderName = "C:\PetesStuff\01 Backup"

$MyOutputFile = "C:\PSOutputA.txt"

get-childitem $MySourceFolderName -recurse |where-object {$_.length -gt 15000} | where-object {$_.extension -eq ".dll"} |
    sort-object -property Length -descending | Format-Table Name, Length -auto| Out-File -filepath  $MyOutputFile

So far, this works, but I also want to include the File version, which can't be accessed in the same way that Name and Length can.

Can anyone help me out, please?

Thanks in advance

Pete

Ok, can do! What you want is Get-Command (I don't know why, but I do know it works). We can put it in a little impromptu hash table in the Format-Table command. Also, I'm going to move the second Where statement to a -filter so the provider filters that for you, and toss in some aliases because this is such a very long line.

GCI $MySourceFolderName -recurse -Filter "*.dll" | ?{$_.length -gt 15000} | sort -property Length -descending |
    FT Name, Length, @{l="File Version";e={(Get-Command $_.FullName).FileVersionInfo.FileVersion}} -auto| Out-File -filepath  $MyOutputFile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM