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-Nounsyntax- e.g.,
Get-HelpInvoke-CommandNew-ItemSet-Content
- e.g.,
- scripts use
.ps1extension - supports redirection
- define variable:
$var = value- uses
$in the definition
- uses
- 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