How to use the command 'powershell' (with examples)
The ‘powershell’ command is used to launch the Windows PowerShell, which is the command-line shell and scripting language provided by Microsoft. It allows users to automate tasks and manage Windows systems through commands and scripts.
Use case 1: View the documentation for the command referring to the latest, cross-platform version of PowerShell (version 6 and above)
Code:
tldr pwsh
Motivation:
When working with the latest version of PowerShell, it’s important to have access to the most up-to-date documentation. By using the ’tldr pwsh’ command, users can quickly view a concise summary of the command and its usage, making it easier to find the information they need.
Explanation:
tldr
: The ’tldr’ command stands for “too long, didn’t read” and provides a simplified and concise version of command documentation. It is commonly used as a quick reference tool.pwsh
: ‘pwsh’ is the cross-platform version of PowerShell (formerly known as PowerShell Core). The ’tldr pwsh’ command specifically retrieves documentation for this version.
Example output:
pwsh
Launch PowerShell Core.
- Open a new PowerShell Core window:
pwsh
- Run a script from a file:
pwsh ./script.ps1
Use case 2: View the documentation for the command referring to the legacy Windows PowerShell (version 5.1 and below)
Code:
tldr powershell -p windows
Motivation:
In some cases, users may still be working with the legacy version of Windows PowerShell (version 5.1 and below). It’s important to have access to the appropriate documentation for this version to ensure compatibility and accurate usage of commands.
Explanation:
tldr
: The ’tldr’ command stands for “too long, didn’t read” and provides a simplified and concise version of command documentation. It is commonly used as a quick reference tool.powershell
: The ‘powershell’ command is used to launch the Windows PowerShell.-p windows
: The ‘-p’ option is used to specify the platform for the command documentation. In this case, ‘windows’ is specified to retrieve the documentation for the legacy Windows PowerShell.
Example output:
powershell -p windows
Launch Windows PowerShell.
- Open a new Windows PowerShell window:
powershell
- Run a script from a file:
powershell ./script.ps1
Conclusion:
The ‘powershell’ command is a powerful tool for managing and automating tasks in a Windows environment. By using the ’tldr’ command with the appropriate options, users can quickly access the documentation they need for both the latest cross-platform PowerShell and the legacy Windows PowerShell. This makes it easier to find the relevant command usage and helps improve productivity.