Getting the folder and sub folder information in a particular drive or path through power shell

The below Powershell query will extract the folder and sub folder info in the given path. I just mention here folder  names -path showing as "MainFolder" and "SubFolder". In this place you provide your needed folders.

-Exclude:  This is a parameter to which we need to pass extension of files, which we are expecting not to show in the result set.

Clear
Get-ChildItem `
-Path \\MainFolder\Sub\Sub1 `
-Exclude *.dtsx,*.sql*,*.onepkg*,*.docx*,*.doc*,*.log* -Recurse|
Where-Object {$_.Name -like "*Full_*"}

#Will provide DIFF info
#clear
Get-ChildItem `
-Path \\MainFolder\Sub\Sub1 `
-Exclude *.dtsx,*.sql*,*.onepkg*,*.docx*,*.doc*,*.log* -Recurse|
Where-Object {$_.Name -like "*Diff_*"}

# The below query will handle above both the queries.

clear
Get-ChildItem `
-Path E:\SQLBackups\Backups `
-Exclude *.dtsx,*.sql*,*.onepkg*,*.docx*,*.doc*,*.log* -Recurse|
Where-Object {($_.Name -like "*Full_*") -or ($_.Name -like "*Diff_*")}|
Select-OBject Directory,Name,LastWriteTime|
Sort-Object -Property LastWriteTime -desc  


Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server