PowerShell is a cross-platform task automation and configuration management framework, consisting of a command-line shell and scripting language.
Unlike most shells, which accept and return text, PowerShell is built on top of the .NET Common Language Runtime (CLR), and accepts and returns .NET objects. This fundamental change brings entirely new tools and methods for automation.
PowerShell commands are known as cmdlets.
To list the content of current directory we use : Get-Chiditem
there are various other options to:
-Path : to specify path or one or more location, even wildcard to
-File / -Directory : to get list of file or directory
-Filter : specifies a filter to qualify the Path parameter.
-Recurse : Gets the item in the specific locations and in all child items of the locations.
-Hidden : to get only hidden item
-ErrorAction SilentlyContinue : Specifies what action to take if the command encounters an error.
eg: Get-childitem -Hidden -File -ErrorAction SilentlyContinue
to view hidden files in current directories
Another cmdlets is : Get-Content
this allow to read content of a file
eg: Get-Content -Path file.txt
TO findout number of words in a file we can use Get-Content and pipe the result to Measure Object cmdlet.
eg: Get-Content -Path file.txt | Measure-Object -Word
To get the exact position of a string within the file, you can use the following command: (Get-Content -Path file.txt)[index]
To change diectories use : Set-Location
eg: Set-Location -Path c:\users\administratoe\desktop
to search a perticular file of pattern : Select-String
eg: Select-String -Path 'c:\users\administrstor\desktop' -Pattern "*.pdf*"
we can always use Get-Help to view about the cmdlet.
eg: Get-Help Select-String