One of the key benefits of PowerShell is its object-oriented nature. Instead of working with text-based output like traditional command-line interfaces, PowerShell returns objects that can be easily manipulated using its built-in cmdlets (pronounced “command-lets”). This makes it easy to automate complex tasks, as administrators can pipe the output of one cmdlet to another, building up a chain of commands that perform a series of operations on an object.
Commands To Find Other Commands
I consider this set of commands very useful because they are used to discover other commands. These commands help in discovering syntax, usage, and members of other commands so you don’t have to memorize the full commands catalog. Here are the most useful and frequently used commands that you must know:
Commands | Description |
Get-Member | Gets the properties and methods of objects. You can use following parameters to this command: -Name, -InputObject, -MemberType, -Static, -View |
Get-Command | Sets the maximum number of digits allowed in the integer portion of a numberThe Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, filters, scripts, and applications. Get-Command gets the commands from PowerShell modules and commands that were imported from other sessions |
Get-Help | Helps you learn how to use commands. Following parameters can be used: -Full, -Detailed, _-Examples, -Online, -Parameter, -ShowWindow |
Essential PowerShell Commands
Here is a list of basic PowerShell commands that you should know.
Commands | Description |
Set-Location | This cmdlet sets the working location to a specified location. That location could be a directory, a subdirectory, a registry location, or any provider path. Used as an alternative to the CD command. Parameter -Path |
Get-ChildItem | Gets the items and child items in one or more specified locations. Parameter -Path |
Set-ExecutionPolicy | Scripting is disabled by default to prevent malicious scripts from executing in the PowerShell environment. The Set-ExecutionPolicy cmdlet’s default scope is LocalMachine, which affects everyone who uses the computer. To change the execution policy for LocalMachine, start PowerShell with Run as Administrator. You can set one of four security levels (a) Restricted (b) All Signed (c) Remote Signed (d) Unrestricted |
Get-ExecutionPolicy | Gets the execution policies for the current session. To display the execution policies for each scope in the order of precedence, use Get-ExecutionPolicy -List. To see the effective execution policy for your PowerShell session use Get-ExecutionPolicy with no parameters |
Get-Service | Gets the processes that are running on the local computer |
Get-Process | Gets the services on the computer |
Export-CSV | Lets you export data to a CSV file. e.g. ‘Get-Command | Export-CSV Commands.csv’ |
ConvertTo-Html | You can use this cmdlet to display the output of a command in a Web page. The command takes in the output file you want to convert and the filename you want to save it with. E.g. Get-Command | ConvertTo-Html > Commands.html |
Get-Module | The Get-Module cmdlet lists the PowerShell modules that have been imported, or that can be imported, into a PowerShell session. Without parameters, Get-Module gets modules that have been imported into the current session |
Get-Module -ListAvailable | This command gets the modules that are installed on the computer and can be imported into the current session. Get-Module looks for available modules in the path specified by the $env:PSModulePath environment variable |
Get-InstalledModule | This cmdlet gets PowerShell modules that are installed on a computer using PowerShellGet |
Copy-Item | This cmdlet copies an item from one location to another location in the same namespace. To copy files and folders, type Copy-Item followed by the source -Path, -Destination parameter, and destination address. e.g. Copy-Item “E:\Directory1” -Destination “E:\Directory2” -Recurse |
Move-Item | This cmdlet moves an item, including its properties, contents, and child items, from one location to another location. The locations must be supported by the same provider. e.g. Move-Item -Path “E:\Folder1” -Destination “E:\Folder2” |
Get-Content | This cmdlet lets you view the content of an item item without using a text editor. E.g. Get-Content “E:\Folder1\Test.txt” |