0% found this document useful (0 votes)
93 views3 pages

Powershell Syntex

This document provides an overview of key PowerShell concepts and commands across several categories: 1. Command line parameters, pipelines, objects, looping commands, date/time formatting, redirection, statements, and tab completion are discussed. 2. Variables, arrays, hash tables, automatic variables, preference variables, environment variables, and PowerShell providers are covered. 3. Evaluating expressions, data types, methods, operators, concatenation, regular expressions, replacement, and wildcards are examined. 4. Functions, modules, scriptblocks, advanced functions, and templates are outlined. 5. Example scripts and functions for tasks like conversions, directory navigation, file operations, backups, networking, inventory, and

Uploaded by

Naveenkumar K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views3 pages

Powershell Syntex

This document provides an overview of key PowerShell concepts and commands across several categories: 1. Command line parameters, pipelines, objects, looping commands, date/time formatting, redirection, statements, and tab completion are discussed. 2. Variables, arrays, hash tables, automatic variables, preference variables, environment variables, and PowerShell providers are covered. 3. Evaluating expressions, data types, methods, operators, concatenation, regular expressions, replacement, and wildcards are examined. 4. Functions, modules, scriptblocks, advanced functions, and templates are outlined. 5. Example scripts and functions for tasks like conversions, directory navigation, file operations, backups, networking, inventory, and

Uploaded by

Naveenkumar K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Parameters Command Line Parameters param() and $args[]

Pipelines Pass objects down the pipeline.


Objects Working with objects.
Looping commands: Do, foreach, ForEach-Object, Switch, While
Date&Time Date and Time Format patterns (DateTimeFormatInfo)
Redirection Spool output to a file.
Statements Looping, If-Then-Else.
Tab Completion for Cmdlets, Filenames & Variables.
Transaction Manage transactions.

Variables

Create Variables and assign values - basic Operators: + - / =


Arrays and Hash tables.
Automatic variables ($_, $Args etc)
Preference variables Verbosity, Confirmations, ErrorAction,
$Debug
Ref vars Pass a reference variable to a function.
Environment variables ($Env:) & PowerShell providers.

Evaluate expressions

Escape chars, delimiters, Here Strings and "quotes".


Comparison -like, -lt, -gt, -eq, -ne, -match
DataTypes PowerShell data types.
Methods ToUpper(), PadRight(), Split(), Substring(),
Replace() etc.
.Net Math Round(), Ceiling(), Max(), Min()
Operators Format strings and arrays @( ) -f [ ] $( ) ::
&
Concat Several methods to combine strings together.
Regular Expressions Search and/or Replace.
Replace Basic Search/Replace in strings and files.
Wildcards Match multiple items.

Functions and Modules

Scriptblock A collection of statements: { … }


Functions and Filters Write a named block of code.
Function Input Processing (Begin..Process..End)
Advanced Functions a template to copy.
Modules Combine functions into a module for easy re-use.

Example scripts and functions

Base36 Convert numbers to/from base 36.


CD - Jump to the previous working directory.
DelOlder Delete files and folders older than n days.
DisplayRes Get the display resolution of multiple
computers.
Open Here Open PowerShell from any folder.
Check-Backups Check multiple locations for files that have
changed.
Get-Bandwidth List the average IO for a Network interface.
Get-DiskSpace List the free disk space for multiple computers.
Get-OSVersion Get the OS and Service pack level of a remote
machine (inventory).
Get-Programs List Installed Software (Add/Remove programs)
Get-Uptime Get the system Uptime for one or more computers.
LoggedOn Find who is logged into a machine.
LastLogon Find when an account last logged in.
MsgBox A function to display messages in a popup
message box.
Password expiry Reminder email.
pshInfo List Ram, Disk Space, Service pack, Uptime.
psp PowerShell Ping.
Set-LastWrite Reset Folder Last Modified to the most recent
file in the folder.
#requires Prevent a script from running without a required
element.
ServiceStatus List installed services and service status.
set-eol Change the line endings (CR/LF) of a text file.
StampMe Rename a file with the current Date/Time.
Touch Change the date/time of a file/folder.
Video Converter A simple GUI front end for the FFmpeg video
converter (compress/resize).

Reference / How to

Run a script How to run a .ps1 script by calling


PowerShell.exe
Elevate Run with elevated permissions (As Admin).
Comments How to comment your scripts.
Circular Find circular nested AD groups.
Event IDs The most common Windows Event IDs.
Keyboard Keyboard shortcuts.
LDAP Lightweight Directory Access Protocol (LDAP)
queries
PS verbs Naming convention (Technet)
$Profile The PowerShell startup $Profile.
Prompt Configure the PowerShell prompt.
PS Remoting Run PowerShell on remote machines.
Template Starting point for new PowerShell scripts.
Verbs Approved Verbs for PowerShell
PS v4.0 PowerShell Cmdlet availability on Windows 7 vs
Win8.
OS Version How to retrieve the OS version in PowerShell.

See also: Links to PowerShell Websites, Utilities and Books.

You might also like