Managing Systems With PowerShell
Managing Systems With PowerShell
PowerShell
Agenda
What is PowerShell?
V2 Community Technology Preview (CTP)
Learning PowerShell
Automating with PowerShell
Windows PowerShell
New command-line shell and scripting language
Where Cmdlet
Cmdlet
Sort
Cmdlet
Format
Windows PowerShell Pipeline Processor
Demo: Short Introduction to
PowerShell
Jeffrey P Snover
Partner Architect
State of the Software
Phenomenal rate of adoption
> 1.55 Million downloads in < 1 year
Exchange 2007, MOM 2007
Virtual Machine Manager 2007
Lotus Domino Transporter Suite
Data Protection Manager
Compute Cluster Tool Pack
Windows Server
Backup
Good ISV pickup
> 20 new internal partners
CEC 2009 requirement
Won both Best of TechEd and Teched Attendees Pick
State of the Software - Community
Active and useful Newsgroups and Forums
25 Codeplex projects (2 in the top 25 most active)
Strong group of MVPs
Strong community tools
Tower of Power
Productivity
Exchange 2003 (VBScript) E12 (Monad Script)
Mailbox
Statistics
Set listExchange_Mailboxs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\
COMPUTERNAME\ROOT\MicrosoftExchangeV2").InstancesOf("Exchange_Mailbox") get-mailboxstatistics
For Each objExchange_Mailbox in listExchange_Mailboxs –server $servername
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
move-storagegrouppath
StorGroup.DataSource.Open "LDAP://" + DCServer + "/ CN=First Storage
Group,CN=InformationStore,CN=" + Server + ",CN=Servers,CN=First Administrative
-identity “First Storage
Group, CN=Administrative Groups,CN=First Organization, CN=Microsoft
Exchange,CN=Services, CN=Configuration," + DomainName
Group“
StorGroup.MoveLogFiles("C:\newlogPath", 0)
–log "C:\newlogPath”
Recipient
Mgmt
Dim objMailbox As CDOEXM.IMailboxStore
enable-mailbox
Set objMailbox = GetObject("LDAP://" + DCServer + "CN=FOO,CN=users," + DomainName) -identity domain\FOO
objMailbox.CreateMailbox "LDAP://" + DCServer + "/CN=Private MDB,CN=First Storage –database “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
Group\Private MDB”
Partner
Dmitry Sotnikov
New Product Research Manager
Quest Software
Announcing :
PowerShell V2 Community
Technology Preview (CTP)
Availability /Applicability
The PowerShell V2 CTP is not for everyone
Read this PowerShell Team blog entry:
http://blogs.msdn.com/powershell/archive/2007/11/02/ctp-watch-this
-space.aspx
PowerShell V2 Themes
Production Scripting
Community Feedback
PowerShell V2 Themes
• Remoting
• Mobile Object Model
• Background Jobs
• Restricted Runspaces
• Eventing (coming soon)
• Graphical PowerShell
• Script Cmdlets
• Script Internationalization/Data Language
• Debugging
• Packages and modules (coming soon)
Production Scripting
Features
• Language enhancements
• Improved adapters
• New/improved cmdlets
Community Feedback
Call To Action
Command Function
Get-Help Help about PowerShell commands and topics
Get-Command Get information about anything that can be
invoked
Get-Member Show what can be done with an object
Get-PSDrive Shows what object stores are available
Demo: Discovery Utilities
Jeffrey P Snover
Partner Architect
Utilities – Object Manipulation
Command Action
Compare Compare 2 sets of objects
Group Split a set of objects into groups
Measure Measure some property of a set of objects
Select Select a set of properties from a set of objects
Sort Sort objects
Tee Make a copy of a set of objects
Where Select a subset of objects
Demo: Object Manipulation
Utilities
Jeffrey P Snover
Partner Architect
Transformation and Output
Commands Functions
Format Convert objects into formatting records
-Custom
-List
-Table
-Wide
Out Convert formatting records into output-specific directives.
-File
-Host
-Printer
-String
Export/Import Converts objects into and out of file formats
-CliXML
-CSV
ConvertTo Converts object into other objects
-HTML
Demo: Transformation and
Output Utilities
Jeffrey P Snover
Partner Architect
PowerShell Scripting
Instrumentation
Text
COM
.NET
Cmdlets
Object types
WMI
XML
ADO
ADSI
Demo: PowerShell Scripting
Jeffrey P Snover
Partner Architect
Summary/Call to Action
Now available at: www.microsoft.com/downloads
Search for PowerShell
Try it, Deploy it, Use it, Share
Allows admins to easily access and leverage a huge API set because of
scriptability, utilities and formatting
Scripting with XML
PowerShell provides native XML support
Native datatype
$x=[xml]"<a><b><c>TEST</c></b></a>“
$b =[xml](type c:\i386\mssecure.xml)
Native syntax to access “data” view of properties
$b.BulletinDataStore.Bulletins.Bulletin[0]
Access to XML methods
$b.BulletinDataStore.SelectNodes(“//Patch”)
XML properties available through PSBase property
$b.BulletinDataStore.PSBase.innerXml
Scripting with Text
Invoke existing tools
Existing command run directly after variables are expanded
Harvest data from existing tools
Parse output into variables using text utilities.
Pipe data to SELECT and use –FIRST and –LAST
Select-String <REGEX> <Path>
Dir | Select-String <REGEX>
[DateTime]”12/25/2006 7:00”
([DateTime]”12/25/2006 7:00”).AddDays(-30)
Use functions/scripts to wrap the commands and convert output to objects or provide
standard syntax
Safely process text
Use CLR types via Windows PowerShell to safely parse text
[URI]” http://blogs.msdn.com/powershell/archive/2006/04/25/583234.aspx”
Allows admins to get 2-10x more power out of existing commands because
of scriptability