Explain PowerShell cmdlets and their syntax structure.

Beginner

Answer

PowerShell cmdlets follow a consistent Verb-Noun syntax structure, making them intuitive and predictable.

Common verbs:

  • Get (retrieve information)
  • Set (modify properties)
  • New (create objects)
  • Remove (delete objects)
  • Start/Stop (control services/processes)

Syntax structure:

Verb-Noun -Parameter Value -Switch

Examples:

Get-Service -Name "Spooler"
Set-Location -Path "C:\Windows"
New-Item -ItemType Directory -Name "TestFolder"
Stop-Process -Name "notepad" -Force

Parameters: Modify cmdlet behavior
Switches: Boolean parameters (present or not)
Pipeline: Cmdlets can be chained using the pipe operator (|)