Windows PowerShell


PowerShell (PS) is a command shell and scripting language built on the .NET Framework that uses cmdlets for Windows automation.

  • similar command line capabilities as UNIX and Linux systems
  • Early editions of Windows utilized the command prompt (cmd.exe)
    • still supported by new editions of Windows
  • PowerShell offers far greater capability and is well suited to scripting
  • syntax is different than Linux shell scripting
  • uses cmdlets that utilize a Verb-Noun syntax
    • e.g.,
      • Get-Help
      • Invoke-Command
      • New-Item
      • Set-Content
  • scripts use .ps1 extension
  • supports redirection
  • define variable: $var = value
    • uses $ in the definition
  • specify variable type: [int]$var = value

 Windows provides the PowerShell ISE (Integrated Scripting Environment) which is designed to help craft scripts.

Example

New-Item MyFile.txt -ItemType File
Add-Content .\MyFile.txt 'Hello, World'
Get-Content .\MyFile.txt

Redirection Example

Get-EventLog -LogName Security -InstanceId 4625 > logonfails.txt