PowerShell Jeffrey P. Snover Partner Architect Agenda Past Present Future UNIX Composable Management Successful but very inefficient A|B|C The heart of Unix composable management Means that A didn’t do.

Download Report

Transcript PowerShell Jeffrey P. Snover Partner Architect Agenda Past Present Future UNIX Composable Management Successful but very inefficient A|B|C The heart of Unix composable management Means that A didn’t do.

PowerShell
Jeffrey P. Snover
Partner Architect
Agenda
Past
Present
Future
UNIX Composable Management
Successful but very inefficient
A|B|C
The heart of Unix composable management
Means that A didn’t do what you wanted to do
WHY?
A is a tight coupling of
Get Objects => Process Objects => Output as text
“| B | C” uses prayer-based parsing to recreate the object so you can do one
of the steps differently
.NET allows us to do better
Pipeline structured objects instead of text
Pipeline should be between get/process/Output
Composable Data Model Progression
UNIX:
Standardized data encoding (ASCII files) allows the emergence of
a set of domain-neutral utilities for composition and manipulation
(e.g. sed, awk, grep)
SQL:
Standardized data forms (Tables) allow the emergence of a set of
domain-neutral utilities for composition and manipulation (e.g. join,
query, groupby)
.NET Reflection:
Standardized object forms (.net objects) allow the emergence of a
set of domain-neutral utilities for composition and manipulation
PowerShell Dynamic objects
.Net Reflection model applied to XML, WMI, ADSI, ADO, etc
Extended types to ease composition, organize folklore, and
facilitate discovery
Economics for Developers
Traditional
Model
Dev Costs
Test Costs
User Training
Common Functions
Individual Cmds
Common Engine, Language & Utilities
# of commands Delivered
Present: Windows PowerShell
New command-line shell and scripting language
•
•
•
•
As interactive and composable as BASH/KSH
As programmatic as Perl/Python/Ruby
As production oriented as AS400 CL/VMS DCL
Allows access to data stores as easy to access as filesystem
Demo: Short Introduction
Jeffrey P. Snover
Partner Architect
The Difference is OBJECTS!
Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table
Common Windows PowerShell Parser
Format
Cmdlet
Sort
Cmdlet
Where Cmdlet
Get-Process
Cmdlet
Windows PowerShell Pipeline Processor
GUI
CLI
Setup
WinForms
WinForms
ADO.Net
Early-bound objs
PowerShell Data Provider
PowerShell Engine
Exchange cmdlets
Configuration Data Access
Process
boundary
MAPI
Store
Registry
AD
Meta
base
Scripts
Filters
Functions
Script Cmdlets [New in V2]
Ad Hoc
Run at the command line
Simple BASH style
Parameters are not named or typed
Formal
Parameters are named, typed, have initializers
Sophisticated
Rich error handling
Support –Verbose, -Debug, -Confirm, -Whatif
Digitally signed
Styles of Scripting
Jeffrey Snover
Windows Management Partner Architect
Agenda
Past
Present
Future
State Of The Software
Phenomenal rate of adoption
PowerShell Downloads
2.5
Millions
2
1.5
1
0.5
Over 2 million downloads in
less than 18 months
Windows XP, Windows Vista,
Windows Server 2003
and 2008
Adopted by Exchange, SQL,
SCOM, SCVMM, and
SCDPM
CEC 2009 requirement
Dozens of 3rd party tools,
ISVs, and partners
Citrix, VMWare, Websphere, etc
0
Strong community
engagement, 27 PowerShell
MVPs
Tower Of Power
PowerShell books
Now available in
Japanese
German
French
More…
2007
2008
Mailbox
Statistics
Exchange 2003 (VBScript)
E12 (Monad Script)
Set listExchange_Mailboxs =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2").
InstancesOf("Exchange_Mailbox")
get-mailboxstatistics
–server $servername
For Each objExchange_Mailbox in listExchange_Mailboxs
WScript.echo "AssocContentCount
=” + objExchange_Mailbox.AssocContentCount
WScript.echo " DateDiscoveredAbsentInDS =” + objExchange_Mailbox.DateDiscoveredAbsentInDS
WScript.echo " DeletedMessageSizeExtended =” + objExchange_Mailbox. DeletedMessageSizeExtended
WScript.echo " LastLoggedOnUserAccount =” + objExchange_Mailbox. LastLoggedOnUserAccount
WScript.echo " LastLogoffTime =” + objExchange_Mailbox. LastLogoffTime
WScript.echo " LastLogonTime
=” + objExchange_Mailbox. LastLogonTime
WScript.echo " LegacyDN =” + objExchange_Mailbox. LegacyDN
WScript.echo " MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayName
WScript.echo " MailboxGUID
=” + objExchange_Mailbox. MailboxGUID
WScript.echo " ServerName
=” + objExchange_Mailbox. ServerName
WScript.echo " Size =” + objExchange_Mailbox. Size
WScript.echo " StorageGroupName
=” + objExchange_Mailbox. StorageGroupName
WScript.echo " StorageLimitInfo
=” + objExchange_Mailbox. StorageLimitInfo
WScript.echo " StoreName
=” + objExchange_Mailbox. StoreName
WScript.echo " TotalItems
=” + objExchange_Mailbox. TotalItems
Next
Database
Mgmt
Dim StorGroup as New CDOEXM.StorageGroup
StorGroup.DataSource.Open "LDAP://" + DCServer + "/ CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group,
CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services,
CN=Configuration," + DomainName
StorGroup.MoveLogFiles("C:\newlogPath", 0)
Recipient
Mgmt
Dim objMailbox As CDOEXM.IMailboxStore
Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName)
objMailbox.CreateMailbox "LDAP://" + DCServer + "/CN=Private MDB,CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative Group,
CN=Administrative Groups,CN=First Organization, CN=Microsoft Exchange,CN=Services,
CN=Configuration," + DomainName
move-storagegrouppath
-identity “First Storage
Group“
–log "C:\newlogPath”
enable-mailbox
-identity domain\FOO
–database “First Storage
Group\Private MDB”
Agenda
Past
Present
Future
PowerShell Architecture
User
Experience
Engine
Managed
Elements
Cmdlets
Shell
APIs
WMI
COM
Language
Execution Context
.NET
XML
ADO
Debugger
Object Mgr
ADSI
Native Commands
PowerShell V2 Themes
GUI over PowerShell
Production Scripting
Universal Code Execution Model
Community Feedback
PowerShell V2 Themes
Admin GUIs layer on top of PowerShell
CLI & GUI
Agility in delivering new GUIs
Ensures automation
GUI teaches command line
Standardizes access to managed elements
GUI over PowerShell
GUI Over PS: Features
User
Experience
Graphical
PowerShell
Shell
Engine
Cmdlets
APIs
Out-Gridview
Language
Debugger
Managed
Elements
WMI
COM
New APIs
Execution Context
.NET
XML
Runspace
Pooling
ADO
Object Mgr
ADSI
Thread Control
Native Commands
GUI Over PowerShell
22
PowerShell V2 Themes
Scripts are
Easy to use
Safe to operate
Easy to share
Easy to support
Production Scripting
Production Scripting: Features
User
Experience
Script Cmdlets
Shell
Engine
APIs
Debugger Enhancements
Data
Language
Debugger
Language
Execution Context
Managed
Elements
Cmdlets
Script
Cmdlets
WMI
COM
Native
Code
.NET
XML
Modules
ADO
Object Mgr
ADSI
Transactions
Native Commands
Production Scripting
Jeffrey Snover
Partner Architect
MSD Solutions and Platforms
25
PowerShell V2 Themes
Expressions, Commands, and ScriptBlocks can
run
In the foreground or background
On one or more machines
Over a LAN or a WAN
In restricted or unrestricted environments
Using short or long connections
Using impersonation or supplied credentials
Initiated by user input or by events
Universal Code Execution Model
UCCE Features
User
Experience
Managed
Elements
Engine
Remoting
Shell
Cmdlets
APIs
Background Jobs WMI
COM
Eventing
Language
Debugger
Execution Context
Restricted
Runspaces
Mobile
ObjectObject
Mgr
Model
.NET
XML
ADO
ADSI
Native Commands
Mobile Objects Model
Islands of optimization in a sea of
interoperability
Whenever possible, use live .NET objects
Use typed property bags everywhere else
Live objects get serialized at runspace borders
Typed property bags using 22+ core datatypes
Everything else is converted using ToString()
Process can be tweaked with typeXML entries
Automatically deserialized into typed property
bags on receipt
Type: Deserialized.OriginalType
PSComputerName
Universal Code
Execution
Jeffrey Snover
Partner Architect
MSD Solutions and Platforms
29
PowerShell V2 Themes
Respond to community feedback
Enhance the language
Tweak the engine
Add and enhance Cmdlets
Community Feedback
Community Feedback: Features
User
Experience
Language
Shell
Enhancements
Engine
Managed
Elements
Cmdlets
APIs
WMI
COM
Language
Debugger
Improved
Execution
Context
Object
Adapters
WMI++
Object Mgr
ADSI
.NET
XML
ADO
New Cmdlets
Native Commands
New Cmdlets (So Far)
Remoting:
Invoke-Command
New-Runspace
Get-Runspace
Push-Runspace
Pop-Runspace
Remove-Runspace
Converting Types:
Add-Type
ConvertTo-Csv
ConvertFrom-Csv
ConvertTo-Xml
ConvertFrom-StringData
Event Viewer and ETW
Logs:
Get-Event
Script Internationalization:
Import-LocalizedData
Modules:
Add-Module
Get-Module
Remove-Module
Export-ModuleMember
Debugging:
Set-PSBreakpoint
Get-PSBreakpoint
Enable-PSBreakpoint
Disable-PSBreakpoint
Remove-PSBreakpoint
Get-PSCallStack
Eventing:
Register-ObjectEvent
Register-PSEvent
Wait-PSEvent
Remove-PSEvent
Unregister-PSEvent
Get-PSEvent
New-PSEvent
Get-PSEventSubscriber
Background Jobs:
Start-PSJob
Get-PsJob
Stop-PSJob
Receive-PSJob
Wait-PSJob
Remove-PSJob
Transactions:
Complete-PSTransaction
Start-PSTransaction
Undo-PSTransaction
Use-PSTransaction
WMI:
Register-WMIEvent
Set-WMIInstance
Invoke-WMIMethod
Remove-WMIObject
More Cmdlets:
Clear-History
Get-Random
Out-GridView
Set-StrictMode
Update-List
Wait-Process
WMI+++
Cmdlets
Get-WmiObject, Remove-WmiObject
Set-WMIInstance
Invoke-WmiMethod
Register-WMIEvent
New parameters
-Impersonation, -Authentication, -Locale,
-EnableAllPrivileges, -Amended, -DirectRead,
-Authority
-AsJob and -ThrottleLimit (!)
Connection settings stay with the object [bug fix]
Newsgroup: Microsoft.Public.Windows.PowerShell
Team blog:
http://blogs.msdn.com/PowerShell/
PowerShellCommunity.Org:
http://www.PowershellCommunity.Org
Channel 9
http://channel9.msdn.com/tags/PowerShell
Wiki
http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWiki
Script Center:
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
CodePlex:
http://codeplex.com/Project/ProjectDirectory.aspx?TagName=powershell
Many excellent books
Manning Press book by PowerShell Dev Lead Bruce Payette: PowerShell in Action
http://manning.com/powershell/
O’Reilly book by PowerShell Dev Lee Holmes – Windows PowerShell Cookbook
http://www.oreilly.com/catalog/9780596528492/index.html
Questions?
http://blogs.msdn.com/powershell
© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market
conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.
MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.