Nicolas Blank Zlatan Dzinic Exchange amp SharePoint MVP WTB202 Agenda What is PowerShell Why do developers care Development scenarios and examples PowerShell Community Resources Demos in between ID: 797970
Download The PPT/PDF document "PowerShell For Developers" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Slide2PowerShell For Developers
Nicolas Blank – Zlatan Dzinic
Exchange & SharePoint MVP
WTB202
Slide3Agenda
What is PowerShell
Why do developers care
Development scenarios and examples
PowerShell Community Resources
Demos – in between
Slide4Present: 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
Slide5The Difference is OBJECTS!
Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table
Get-Process
Cmdlet
Common Windows PowerShell Parser
Windows PowerShell Pipeline Processor
Where
Cmdlet
Sort
Cmdlet
Format
Cmdlet
Slide6PowerShell Architecture
Slide7demo
Slide8State Of The Software
Phenomenal rate of adoption
Over 2 million downloads in less than 18 months
Windows XP, Windows Vista, Windows 7, Windows Server 2003 and 2008
Adopted by Exchange, SQL, SCOM, SCVMM, and SCDPM
CEC 2009 requirement
Dozens of 3
rd
party tools, ISVs, and partnersCitrix, VMWare,
Websphere
, etcStrong community engagement, 27 PowerShell MVPs
Shipped with
Windows Server 2008
Slide9PowerShell
Engine
Exchange cmdlets
Configuration Data Access
AD
Registry
Meta
base
MAPI
Store
Process
boundary
E2007Management ArchitectureEarly-bound objs
WinFormsADO.NetPowerShell Data Provider
WinFormsCLIGUI
Setup
Slide10Forms of Scripting
Scripts
Filters
Functions
Script Cmdlets [New in V2]
Slide11S
tyles
of Scripting
Ad Hoc
Run at the command lineSimple BASH style
Parameters are not named or typedFormalParameters are named, typed, have initializers
SophisticatedRich error handlingSupport –Verbose, -Debug, -Confirm, -
WhatifDigitally signed
Slide12A note on Strict mode – In the shell
Allows Typo’s to be caught INSIDE the shell (no IDE)
PowerShell v1
Set-
PSDebug –strict
PowerShell V2 Set-StrictMode –version 1 or Set-StrictMode –version 2.
Slide13Productivity
Exchange 2003 (VBScript)
E2k7 (
PowerShell
Script)
Mailbox Statistics
Set
listExchange_Mailboxs
=
GetObject
("
winmgmts
:{
impersonationLevel
=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2").InstancesOf("
Exchange_Mailbox")For Each objExchange_Mailbox in listExchange_Mailboxs
WScript.echo "AssocContentCount =” + objExchange_Mailbox.AssocContentCountWScript.echo " DateDiscoveredAbsentInDS =” +
objExchange_Mailbox.DateDiscoveredAbsentInDSWScript.echo " DeletedMessageSizeExtended =” + objExchange_Mailbox. DeletedMessageSizeExtendedWScript.echo "
LastLoggedOnUserAccount =” + objExchange_Mailbox. LastLoggedOnUserAccountWScript.echo " LastLogoffTime
=” + objExchange_Mailbox. LastLogoffTimeWScript.echo " LastLogonTime
=” + objExchange_Mailbox. LastLogonTime WScript.echo "
LegacyDN =” + objExchange_Mailbox. LegacyDNWScript.echo "
MailboxDisplayName =” + objExchange_Mailbox. MailboxDisplayNameWScript.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
get-
mailboxstatistics
–server $
servername
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)
move-
storagegrouppath
-identity “First Storage
Group“
–log "C:\newlogPath”
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
enable-mailbox
-identity domain\FOO
–database “First Storage
Group\Private MDB”
Slide14Why Do Developer Care?
Everybody's doing it
Powershell
is based on
.net - chances are if you're in this room you're using
.net todayCEC @MSCan run .Net
code inside PowerShellCan run PowerShell inside managed codeBetter visibility into the Object Model
Find all the instances of a content type in a SiteAutomated or repetitive tasksAdd a web part to a page on 500 sites
Faster Development Cycle
Slide15Developing Faster
Traditional Development
Time wasted during Testing
PowerShell / .NET Hybrid Development
‘Risky’ development done in
PoSH
Code converted to .NET (C#/VB)
Shorter Deploy/Test Cycle
Slide16.Net calls inside PowerShell
PowerShell is
.Net
based and has full access to the entire
.Net stack
Easy to do, direct calls with no need to initialise or wrap
Slide17Demo:
Calling
.Net
libraries inside PowerShell
Slide18PowerShell INSIDE managed Code
PowerShell can be used inside C#
Take advantage of PowerShell
CMDlets
and save coding timeBuild Winforms
GUI’s on top of PowerShellMore……
Slide19Demo:
PowerShell INSIDE managed Code
Slide20How to write a CMDlet
Either as a PowerShell function – shell code
http://technet.microsoft.com/en-us/library/dd315326.aspx
Or a
.net
CMDLET – (compiled code)http://msdn.microsoft.com/en-us/library/dd878294(VS.85).aspx
Slide21PowerShell Community Resources
Slide22PowerShellCommunity.org
Forums
Cmdlet Library
Blogs
Wiki
Script Repository
Software DirectoryUser Group Outreach
Slide23PowerScripting Podcast
Hosts: Jonathan
Walz
& Hal Rottenberg
Online at
PowerScripting.netWeekly dose of News, Resources, Interviews, Tips and more!
Slide24PowerShell Tools
PowerGui.org – Free PowerShell IDE with
intellisense
, code snippets and built in debugging
PowerTab –
intellisense INSIDE the shell http://thepowershellguy.com/blogs/posh/pages/powertab.aspx
Slide25Virtual User Group
Marco Shaw runs a monthly user’s group meeting online using Microsoft Live Meeting
Interviews
Q&A with experts
Check news for upcoming events and Marco’s
get-powershellblog (marcoshaw.blogspot.com)
Slide26PowerShell Newsgroup
Use NNTP server msnews.microsoft.com or web portal
Group name:
microsoft.public.windows.powershell
Slide27#powershell IRC Chat Room
Freenode
IRC network: irc.freenode.net
Web client at
powershelllive.com/
ircOnly for MVPs and cool peopleFree real-time scripting advice
Slide28Microsoft Resources
PowerShell Team Blog
blogs.msdn.com/
powershell
Scripting Guys Script Center
microsoft.com/technet/scriptcenterHub for official documentation
PowerShell Tip of the WeekThe Windows PowerShell ToolboxScript repository and other goodies
Slide29Community Resources
Newsgroup:
Microsoft.Public.Windows.PowerShell
Team blog:
http://blogs.msdn.com/PowerShell
PowerShell Community:
http://www.powershellcommunity.orgChannel 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=powershellBooks
PowerShell in Action by Bruce Payettehttp://manning.com/powershell
Windows PowerShell Cookbook by Lee Holmes http://www.oreilly.com/catalog/9780596528492/index.htmlProfessional Windows PowerShell Programming http://www.wrox.com/WileyCDA/WroxTitle/productCd-0470173939.htmlMany others…
Slide30question & answer
Slide31www.microsoft.com/teched
International Content & Community
http://microsoft.com/technet
Resources for IT Professionals
http://microsoft.com/msdn
Resources for Developers
www.microsoft.com/learning
Microsoft Certification & Training Resources
Resources
Required Slide
Speakers,
TechEd 2009 is not producing
a DVD. Please announce that
attendees can
access session
recordings from Tech-Ed website. These will only be available after the event.
Tech
·Ed
Africa 2009 sessions will be made available for download the week after the event from:
www.tech-ed.co.za
Slide32Related Content
Breakout Sessions (session codes and titles)
Whiteboard Sessions (session codes and titles)
Hands-on Labs (session codes and titles)
Required Slide
Speakers,
please list the Breakout Sessions,
TLC Interactive Theaters and Labs
that are related to your session. Any queries, please check with your Track Owner.
Slide33Track Resources
Resource 1
Resource
2
Resource
3Resource
4
Required Slide
Track Owners
to provide guidance.
Please address any queries to your track owners.
Slide34Required Slide
Complete a session evaluation and enter to win!
10 pairs of MP3
sunglasses
to be
won
Slide35©
2009 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.
Required Slide