Unleashing the Power: A Lap Around PowerShell

Download Report

Transcript Unleashing the Power: A Lap Around PowerShell

Unleashing the
Power: A Lap Around
PowerShell 3.0
PRESENTED BY SARAH DUTKIEWICZ
CENTRAL OHIO DAY OF .NET 2012
DECEMBER 8, 2012
Windows PowerShell 3.0 – System
Requirements & Prerequisites

Operating Systems: Windows 7 SP1, Windows Server 2008 R2 SP1, Windows
Server 2008 SP2, Windows 8, Windows Server 2012

For the Integrated Scripting Environment for PowerShell 3.0 to be installed on
Windows Server 2008 R2 SP1, the ISE feature must be enabled before installing
Windows Management Framework 3.0
Downloading PowerShell 3.0

PowerShell is part of the Windows
Management Framework 3.0 suite.

32-bit & 64-bit installers available.

Windows 8 & Windows Server 2012
already have PowerShell 3.0
installed.

For other supported operating
systems, download PowerShell
from:
http://www.microsoft.com/enus/download/details.aspx?id=3459
5
Core Enhancements

Computer cmdlets

Start-Process

CSV cmdlets

Tee-Object

Get-ChildItem

Test-Connection

Get-Command

Add-Member

Get-Content

Get-History

Measure-Object

Security cmdlets

Select-Object

Select-String

Split-Path
Supports .NET Framework 4.0

Built on CLR 4.0

Adds features/support for:

Networking

Parallel Computing

Management Extensibility Framework (MEF)

Application Compatibility and Deployment

Windows Workflow Foundation (WF)

Windows Communication Foundation (WCF)
Show-Command with the console
D
Updatable Help
• Help Files aren’t installed by
default on Windows 8 and
Windows Server 2012, which
means a smaller starting
footprint for PowerShell.
• Help files are easily installed
and updated with the
Update-Help cmdlet
• No restart is required for
updating Help
documentation.
• Save-Help cmdlet can
download help files to
a file share.
• Developers can add
support for updatable
help to their custom
modules. More in this
Dev Center article.
Automatic ForEach/Implicit ForEach

No more need for the foreach
{ … $_ } notation when
dealing with collections.

While this syntax is no longer
needed, it is still supported.

You can now access
properties collectively as
$collectionname.propertyname
rather than having to iterate
through the collection.

This also works with methods
and not just properties.
D
Simplified Where

Much like the automatic
foreach, the where clause
has been simplified and the
where {…. $_ } notation is no
longer needed.

The old syntax is still
supported but no longer
necessary.

You can now search a
collection with
propertyname
comparisonoperator
searchcriteria
D
Enhanced Tab Completion

New underlying parser and abstract syntax tree


Includes midline tab completion and in-memory parsing tress
Completes cmdlets, parameters, parameter values, enumerations,
.NET Framework types, COM objects, hidden directories
D
New JSON, REST, & HTML Parsing
Support

New cmdlets added to the PowerShell Core include:

Invoke-RestMethod

Invoke-WebRequest

ConvertFrom-Json

ConvertTo-Json
Try these examples:
• Reading the latest titles and published dates from my blog:
Invoke-RestMethod –Uri http://feeds.feedburner.com/codinggeekette | Format-List title,
pubdate
• Reading the categories at NewEgg:
$newegg = Invoke-WebRequest http://www.newegg.com
$newegg.Links | where class –eq “tier1” | select innertext | Get-Unique –AsString
D
Sessions Improvements

Disconnected sessions on remote computers can be reconnected
later without losing state.

Because of this, if a session disconnects due to network connectivity
issues, the session can be resumed once network connectivity has
been reestablished.
Integrated Scripting Environment
Improvements

Intellisense

Rich copy

ShowCommand
window – for
all installed
modules

Block copy

Snippets


Code
outlining

Auto save

 Recent items
NewIseSnippet  Workflows

Get-
Unified
IseSnippet
Console Pane
 Import– combining
IseSnippet
Command
and Output  Brace
windows
matching
D
ISE Improvements (continued)
D
Workflows

Remote monitoring of long-running tasks

Persistence

Robustness – failure recovery

Disconnect, reconnect, and run in disconnected sessions

Workflow Scheduling

Workflow execution and connection throttling
D
Scheduled Jobs

Now integrates with Task Scheduler

Run asynchronously in the background

Can be one-time or recurrent

Can respond to actions and events
D
Scheduled Jobs Example
Workflow Reset-Temp
{
$pathToTemp = "C:\Windows\Temp\*"
Remove-Item -Recurse -Force -Path $pathToTemp
Suspend-Workflow
}
Scheduled Jobs Example
(continued)
Reset-Temp -JobName CLEAR_TEMP -PSPersist:$true
$startuptrigger = New-JobTrigger -AtStartup
$weeklyTrigger = New-JobTrigger -Weekly -DaysOfWeek Monday -At
9am
Register-ScheduledJob -Name ClearTemp -Trigger
$startuptrigger,$weeklyTrigger {
Import-Module PSWorkflow
Resume-Job CLEAR_TEMP
}
Scheduled Jobs Example
(continued)
In Task Scheduler, Under: Task Scheduler Library/Microsoft/Windows/PowerShell/ScheduledJobs
Autoloading Modules

As long as the module is
available, PowerShell 3.0
will automatically load a
module once a cmdlet is
invoked from it.

This example is showing
the module list before
installing PowerShell Web
Access and then the
module list afterwards.
Invoking InstallWindowsFeature triggers
the loading of more
modules, as it is in the
ServerManager module.
D
PowerShell Web Access

Ability to run PowerShell from
a web browser

Prerequisites:


Windows Server 2012
Deployment instructions:
http://technet.microsoft.com
/en-us/library/hh831611.aspx
D
PowerShell Web Access Limitations

Some function keys unsupported, dependent on the browser.

Only top-level progress information is available; nested progress
displays won’t appear.

Input color (foreground and background) cannot be changed.

Anything that writes to the Windows console won’t work, as It isn’t
implemented by PSWA.

Any limitations from a remote PowerShell session (New-PSSession,
Enter-PSSession) apply to PowerShell Web Access as well.
Management OData IIS Extension

Another part of Windows Management Framework 3.0

Allows clients to invoke PowerShell cmdlets remotely using a RESTful
web service accessible via OData.
PowerShell Web Service

Requires Management
Odata feature to be
installed first

Requires Windows Server
2012

Sample requires to be
built on a non-express SKU
of Visual Studio 2010 or
Visual Studio 2012
D
PowerShell Web Service Example

Download sample from:
http://code.msdn.microsoft.com/windowsdesktop/PswsRoleBasedPl
ugins-1c7a7ef1

Sample includes:


PowerShell script to setup Management Odata

Visual Studio solution with sample C# code

PowerShell script to setup the environment and create the endpoint
Custom endpoint should be:
http://localhost:7000/MODataSvc/Microsoft.Management.Odata.svc
D
Microsoft Script Explorer for
Windows PowerShell

Helps find scripts from 
various repositories –
including TechNet
Script Center
Repository,
PoshCode, Bing
Search Repository,
and local or network
file systems

Searches scripts,
modules, snippets,
and how-to
guidance
Can search in large
Focus Areas or drill
down into searching
by category (as
shown right)
D
Microsoft Script Explorer for
Windows PowerShell Prerequisites

Works on 32-bit and 64-bit platforms

Operating system requirements: Windows 7 SP1, Windows 8,
Windows Server 2008 R2 SP1, Windows Server 2008 SP2, Windows
Server 2012, Windows Vista SP2

Additional Requirements: PowerShell ISE, .NET 3.5 SP1, .NET 4
(Standalone or Web Installer)

Download it from the Microsoft Download Center:
http://www.microsoft.com/en-us/download/details.aspx?id=29101
D
Resources

PowerShell 3.0 Quick Reference Guides

New V3 Language Features

Intellisense in Windows PowerShell ISE 3.0

Basic installation guide for Windows PowerShell Web Access

TechNet Radio: The Scripting Guy’s Top 5 PowerShell 3.0 Tips and
Tricks

PowerShell Magazine

Windows PowerShell Blog
Contact Information

Twitter: @sadukie

Facebook: Sarah “sadukie”
Dutkiewicz

LinkedIn:
http://www.linkedin.com/profile/view
?id=27521335

Email: [email protected]

Blog: http://codinggeekette.com
Thanks to
our
AWESOME
sponsors!