This Video Show shows demo and Lab solution for episode "Listing Files & Folders Using PowerShell"
You can come to know about " How to List files and Folders using PowerShell"
Below mentioned are commands and Scripts used in this Video -
Please use this code to practice in your environment as well.
##########################################
##### LAB -1
##########################################
Prepare Demo Environment
Set-Location "D:\PSTraining\PracticeGround"
Remove-Item .\* -Recurse -Force
New-Item .\Dir_Depth1\Dir_Depth2\Dir_Depth3\Dir_Depth4 -ItemType Directory
tree
1..2|% {New-Item -Path . -Name "$("file" + "$_").txt" -ItemType "file"}
1..2|% {New-Item -Path .\dir* -Name "$("file" + "$_").txt" -ItemType "file"}
1..2|% {New-Item -Path .\dir*\dir* -Name "$("file" + "$_").txt" -ItemType "file"}
1..2|% {New-Item -Path .\dir*\dir*\dir* -Name "$("file" + "$_").txt" -ItemType "file"}
1..2|% {New-Item -Path .\dir*\dir*\dir*\dir* -Name "$("file" + "$_").txt" -ItemType "file"}
1..2|% {New-Item -Path .\dir*\dir*\dir*\dir* -Name "$("file" + "$_").log" -ItemType "file"}
(New-Item . -Name hidden1.txt -ItemType file).Attributes += 'Hidden'
##########################################
####### EXAMPLES
########################################
1 Getting child items from a directory
Get-ChildItem -Path .
2 Getting only names of child items from a directory
Get-ChildItem -Path . -Name
3 Getting child items in the current directory and subdirectories
Get-ChildItem -Path .
Get-ChildItem -Path . -Recurse
Get-ChildItem -Path .\*.txt -Recurse
4 Listing only a particulr pattern of files (Example - Log files)
Get-ChildItem -Path .\dir*\dir*\dir*\dir* -Recurse
Get-ChildItem -Path .\dir*\dir*\dir*\dir* -Recurse -Filter *.log
5 Listing Only Files from folder / Path
Get-ChildItem -Path . -Recurse -Name
Get-ChildItem -Path . -File -Recurse -Name
6 Listing Only Directories from folder / Path
Get-ChildItem -Path . -Recurse -Name
Get-ChildItem -Path . -Directory -Recurse -Name
7 Getting Hidden and System files in the current directory and subdirectories
Get-ChildItem -Path .
Get-ChildItem -Path . -force
8 Getting only Hidden, System or ReadOnly files specifically using -Hidden, -ReadOnly or -System parameter
Get-ChildItem -Path .
Get-ChildItem -Path . -Hidden
9 Include or exclude a particular pattern from listing
Get-ChildItem -Path . -file -Recurse -Name
Get-ChildItem -Path . -Include *.txt -file -Recurse -Name
Get-ChildItem -Path . -Exclude *.txt -file -Recurse -Name
10 Getting items from upto a level of subfolders only
Get-ChildItem -Path . -Recurse
Get-ChildItem -Path . -Depth 2
11 Geting non-system files (not directories)
Get-ChildItem . -Attributes !Directory # Listng items which are not directory
Get-ChildItem . -Attributes !Directory+!System # Listng items which are not directory and not System files
Get-ChildItem . -Attributes hidden # Listng items which hidden
##################################################
#### LAB -2
##################################################
Audit department of a company want to get list of ONLY 4 files, that have been created very recently on File Server
**************************** SOLUTION *************************
Get-ChildItem . -File|Sort-Object -Property creationtime -Descending | select creat*,name -First 4
************************************************************************
************************************************************************
Join Me on --
Facebook Group
/ mylearningsonline
Facebook Page
/ mylearningsonline
YouTube Channel
/ mylearningsonline
**************************************************************************
#PowerShell #PowerShellScripting #PowerShellForBeginners #learnPowerShell #PowerShelltraining #PowerShellTutorial #MyLearningsOnline
PowerShell Scripting for Beginners
PowerShell Tutorial for Beginners
PowerShell Full Course
PowerShell Training for Beginners