Question: What is PowerShell?
|
Answer: The PowerShell is a task automation and configuration management framework from Microsoft,
consisting of a command-line shell and associated scripting language built on top of the .NET Framework.
|
Question: What is the difference between PowerShell and Command Prompt?
|
Answer: The Command Prompt (cmd.exe) is the original command-line interpreter for Windows operating systems,
while PowerShell is a more advanced shell that includes a scripting language and supports object-oriented programming,
making it more powerful and versatile than Command Prompt.
|
Question: How do you comment out lines in PowerShell?
|
Answer: In PowerShell, you can use the # character to comment out lines.
Anything following the # symbol on a line is considered a comment and is ignored by PowerShell.
|
Question: How do you declare variables in PowerShell?
|
Answer: Variables in PowerShell are created by simply assigning a value to a name. For example:
$variableName = "value"
|
Question: What are cmdlets in PowerShell?
|
Answer: The Cmdlets (pronounced "command-lets") are lightweight commands used in PowerShell.
They perform specific functions and follow a verb-noun naming convention (e.g., Get-Process, Set-ExecutionPolicy).
|
Question: How do you execute a PowerShell script?
|
Answer: To execute a PowerShell script, you can use the .\ (dot-slash) notation followed by the script file path. For example:
.\script.ps1
|
Question: What is the 'Get-Help' cmdlet used for in PowerShell?
|
Answer: The 'Get-Help' is used to display information about PowerShell
cmdlets, functions, modules, and scripts.
One can use it to learn more about how to use specific commands and their parameters.
|
Question: How do you handle errors in PowerShell?
|
Answer: PowerShell provides several mechanisms for error handling, like:
• Try/Catch blocks
• Error variables like $Error
• '-ErrorAction' parameter for cmdlets to specify how errors should be handled.
|
Question: What is the pipeline in PowerShell?
|
Answer: The pipeline (|) in PowerShell allows you to pass the output of one cmdlet or command
as input to another cmdlet or command.
It enables the chaining of commands for more complex operations.
|