Windows PowerShell
Fundamentals
Steven Murawski Senior Windows Systems Engineer Microsoft MVP
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/
or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
Who I am
•
Name – Steven Murawski
•
Occupation – Senior Windows System
Engineer
•
Blog – UsePowerShell.com
•
Twitter - @StevenMurawski
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
What is PowerShell?
What is PowerShell?
What is PowerShell?
Most importantly though it is an Automation
Tool.
PowerShell offers a unifying management
surface in which to manage your Windows (and
other) environment.
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Terminology
•
Cmdlet
•
Functions
•
Objects
Terminology
•
Cmdlets
– The basic unit of work in PowerShell.
– These are PowerShell’s native commands. – They are called cmdlets (small commands)
because they embrace the Unix philosophy of small tools which can be used compose new solutions
Terminology
•
Functions
– Functions are a series of PowerShell statements (or commands) that are given a name and saved in memory for a particular session.
– There are several types of functions:
• V1 style function
• Filter
Terminology
•
Objects
– PowerShell is an object-based shell.
– Objects are a binding of data and actions.
– What this really means is that when you execute a command, you can more easily ask questions of the result.
– Being object based also gives PowerShell the
ability to provide generalized format, display, and export capabilities.
Terminology
•
Pipeline
– The pipeline is a central concept in PowerShell which allows you to take the output from one command and make it the input for the next command.
– It has long been the case that shell commands can take input from other commands (or files, or other sources).
– The pipeline in PowerShell can leverage the object
based and utilize some components of the runtime to make transitions between commands more effective.
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
The Big Four
•
Navigational And Discovery Commands
– Get-Command – Get-Help
– Get-Member – Get-PSDrive
The Big Four
•
Get-Command
– Get-Command will list any valid command (executables, functions, cmdlets, aliases).
– It can also provide some additional metadata about PowerShell commands and scripts.
The Big Four
•
Get-Help
– This is the “man” equivalent for PowerShell. – Get-Help offers several levels of help
• Basic
• Detailed
• Full
• Examples
The Big Four
•
Get-Member
– Since PowerShell is an object-based shell,
Get-Member allows you to examine the objects output from different commands.
– This is probably the most important discovery command.
The Big Four
•
Get-PSDrive
– PowerShell offers the capability to expose various information sources (providers) like a file system. – Get-PSDrive lists the mapped providers and where
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Working From the Shell
•
Navigating Providers
– Providers offer a way to navigate different data sources via the same commands.
•
Providers
– File System – Registry
Working From the Shell
•
Navigating the File System
– Items and Containers – Item Properties
Working From the Shell
•
Digging in the Registry
– PowerShell provides access to the registry via a provider. This allows the registry to be navigated like the file system.
– Keys and subkeys are represented as items (like files and directories.
– Registry values and data are represented as properties of the items.
Working From the Shell
•
Other Providers
– Built in • Alias • Certificate • File System • Function • Registry • Variable • WSMan – Others • SQL Server • Active DirectoryWorking From the Shell
•
Dealing with Objects
– Formatting Output – Filtering Output – Using the Pipeline
Working From the Shell
•
Formatting Output
– Format-Table – Format-List – Format-Custom – ConvertTo-XML – ConvertTo-HTML – ConvertTo-CSV – Export-CliXML – Export-CSVWorking From the Shell
•
Filtering output
– Native Filtering in Commands
• Usually preferred, but can vary based on the command and data type.
• If the target of the command is remote, filtering could be done at the source.
– Where-Object
• Uses a scriptblock (PowerShell statements surrounded by braces)
• Works on any object in the PowerShell Pipeline
Working From the Shell
•
Using the Pipeline
– PowerShell pipes objects.
– Cmdlets, scripts, and functions can take full objects as arguments.
– Properties of objects can be automatically
mapped to parameters of cmdlets, scripts, or functions.
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Working with Workstations and
Servers
•
Working with WMI
– Get-WMIObject is the key command when working with WMI.
– Get-WMIObject –List
– What’s stored in WMI? Just about everything!
• Hardware information
• System Configuration
• Application Data
Working with Workstations and
Servers
•
Editing the Registry
– Via the Provider
• Can use it locally
• Can use it remotely if PowerShell Remoting is enabled.
– Using .NET
• More familiar to .NET developers.
– Using WMI
Working with Workstations and
Servers
•
Working with Text
– Select-String – Operators • Match • Replace • Split – Regular Expressions
Working with Workstations and
Servers
•
Working with Remote Machines
– WMI
• Available on most machines.
• Requires a knowledge of WMI (which is not very consistent)
– PowerShell Remoting
• Requires Windows XP SP3/Server 2003 SP2 or higher and WinRM
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Working with Active Directory
• ADSI– Available on any machine
– Obscure
• Quest’s AD Cmdlets – Task based
– Excellent Coverage
– Server 2003 Domains or above
– 3rd Party
• Microsoft’s AD Module
– Only available on Windows 7 or Server 2008 R2
– Server 2003 Domains or above.
Working with Active Directory
•
Common Tasks
– Resetting Passwords – Finding Disabled Users
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Working with Exchange
•
Common Tasks
– Monitor Message Queues (Exchange 2003)
– Monitor Message Queues (Exchange 2007/2010) – Identify all ActiveSync Devices Connected
Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
V3 Sneak Peak
•
PowerShell V3 – Windows 8
– Workflows – Resilient Sessions – Disconnected Sessions – Autoloading of Modules – And more…Agenda
•
What is PowerShell?
•
Terminology
•
The Big 4
•
Working from the Shell
•
Workstations and Servers
•
Active Directory
•
Exchange
•
PowerShell V3 Sneak Peak
Q and A
•
I’m sure no one has any questions, so we can
just hang out..
•
But on the off chance that some has any
questions, where can we get some answers?
– PowerShell.Org – ServerFault.com