One liner command to list files with a specific extension in a given path.
Command below will list all the file that will match and display it's file name, file size and the directory where the file is located or found.
The output of PowerShell is redirected to a text file.
$FileExtension=".key"
$FilesDir = get-childitem "d:\CertKeys" -recurse | where {$_.extension -eq $FileExtension } | format-table name,length,Directory -AutoSize
$FilesDir | out-file "d:\certkey.txt"
Or save some few bytes by using the shorter form of the cmdlets.
$FileExtension=".key"
$FilesDir = gci "d:\CertKeys" -recurse | ? {$_.extension -eq $FileExtension } | ft name,length,Directory -AutoSize
$FilesDir | out-file "d:\certkey.txt"
Sample Output:
Name length Directory
---- ------ ---------
ssl.key
ca.key 963 D:\CertKeys\apache\ssl.key
server.key 963 D:\CertKeys\others\ssl.key
snakeoil-ca-dsa.key 672 D:\CertKeys\others\LinuxSrv -others\apache\ssl.key
snakeoil-ca-rsa.key 887 D:\CertKeys\others\LinuxSrv -others\apache\ssl.key
snakeoil-dsa.key 668 D:\CertKeys\others\LinuxSrv ubuntu\apache\ssl.key
snakeoil-rsa.key 887 D:\CertKeys\others\LinuxSrv ubuntu\ssl.key
snakeoil-ca-dsa.key 672 D:\CertKeys\others\apache\mod_ssl
snakeoil-ca-rsa.key 887 D:\CertKeys\others\LinuxSrv ubuntu iptables\mod_ssl
snakeoil-dsa.key 668 D:\CertKeys\others\LinuxSrv\usr-share-apache\apache\mod_ssl
snakeoil-rsa.key 887 D:\CertKeys\others\LinuxSrv -others\usr-share-apache\apache\mod_ssl
Cheers..hope it helps..
Comments
Post a Comment