Question: How do you list all installed modules in PowerShell?
|
Answer: You can list all installed modules in PowerShell using the Get-Module cmdlet. For example:
Get-Module -ListAvailable
|
Question: What is the difference between Write-Host and Write-Output in PowerShell?
|
Answer: You can find the difference below:
• Write-Host sends output to the console, but it cannot be captured or used by other cmdlets in the pipeline.
• Write-Output sends output down the pipeline, allowing it to be captured and used by other cmdlets.
|
Question: How do you list all running processes in PowerShell?
|
Answer: You can list all running processes in PowerShell using the 'Get-Process' cmdlet.
|
Question: What is the 'Where-Object' cmdlet used for in PowerShell?
|
Answer: The 'Where-Object' is used to filter objects in the pipeline based on specified criteria.
It is similar to the Where clause in SQL or the filter function in other programming languages.
|
Question: How do you create a new directory in PowerShell?
|
Answer: You can create a new directory in PowerShell using the 'New-Item' cmdlet with the '-ItemType'
parameter set to Directory. For example:
New-Item -Path C:\Path\To\Directory -ItemType Directory
|
Question: What is the 'ForEach-Object' cmdlet used for in PowerShell?
|
Answer: The 'ForEach-Object' is used to perform an operation on each item in a collection of objects.
It iterates through each object in the pipeline and executes a script block for each one.
|
Question: How do you stop a running script in PowerShell?
|
Answer: One can stop a running script in PowerShell by pressing Ctrl + C in the console window
where the script is running.
This sends a break signal, halting the execution of the script.
|
Question: What is the 'Import-Module' cmdlet used for in PowerShell?
|
Answer: The 'Import-Module' is used to import a PowerShell module into the current session.
Modules contain reusable functions, cmdlets, variables, and other resources
that can extend PowerShell's functionality.
|
Question: How do you get the current directory in PowerShell?
|
Answer: You can get the current directory in PowerShell using the automatic variable '$PWD'
(short for Present Working Directory).
|