Managing Systems with PowerShell Jeffrey P. Snover Partner Architect.
-
Upload
earl-young -
Category
Documents
-
view
238 -
download
0
Transcript of Managing Systems with PowerShell Jeffrey P. Snover Partner Architect.
Managing Systems with PowerShellJeffrey P. SnoverPartner Architect
AgendaWhat is PowerShell?V2 Community Technology Preview (CTP)Learning PowerShellAutomating with PowerShell
Windows PowerShellNew command-line shell and scripting language
Windows PowerShellNew command-line shell and scripting language
As interactive and composable as BASH/KSHAs programmatic as Perl/Python/RubyAs production oriented as AS400 CL/VMS DCLAllows access to data stores as easy to access as filesystem
The Difference is OBJECTS!
Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table
Get-P
rocess
Cm
dle
t
Common Windows PowerShell Parser
Windows PowerShell Pipeline ProcessorW
here
Cm
dle
t
Sort
Cm
dle
t
Form
at
Cm
dle
t
Demo: Short Introduction to PowerShellJeffrey P SnoverPartner Architect
State of the SoftwarePhenomenal rate of adoption
> 1.55 Million downloads in < 1 yearExchange 2007, MOM 2007Virtual Machine Manager 2007Lotus Domino Transporter SuiteData Protection ManagerCompute Cluster Tool PackWindows ServerBackupGood ISV pickup> 20 new internal partners
CEC 2009 requirementWon both Best of TechEd and Teched Attendees Pick
State of the Software - CommunityActive and useful Newsgroups and Forums
25 Codeplex projects (2 in the top 25 most active)Strong group of MVPsStrong community tools
Tower of Power
ProductivityExchange 2003 (VBScript) E12 (Monad Script)
Mailbox Statistics
Set listExchange_Mailboxs = GetObject("winmgmts:{impersonationLevel=impersonate}!\\COMPUTERNAME\ROOT\MicrosoftExchangeV2").InstancesOf("Exchange_Mailbox")
For Each objExchange_Mailbox in listExchange_MailboxsWScript.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. SizeWScript.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”
PartnerDmitry SotnikovNew Product Research ManagerQuest Software
Announcing : PowerShell V2 Community Technology Preview (CTP)
Availability /Applicability
The PowerShell V2 CTP is not for everyoneRead this PowerShell Team blog entry:
http://blogs.msdn.com/powershell/archive/2007/11/02/ctp-watch-this-space.aspx
PowerShell V2 Themes
Universal Code Execution Model
GUI over PowerShell
Production Scripting
Community Feedback
PowerShell V2 Themes
Universal Code Execution Model
• Commands, expressions and ScriptBlocks can be run• in the foreground or background • on one or more machines• over a LAN or a WAN• in unrestricted or restricted environments• using short or long connections• using impersonation or supplied credentials• initiated by user input or by events
Features
Universal Code Execution Model
• Remoting• Mobile Object Model• Background Jobs• Restricted Runspaces• Eventing (coming soon)
Features
GUI over PowerShell
• New hosting APIs• Runspace pooling
Features
Production Scripting
• Graphical PowerShell• Script Cmdlets• Script Internationalization/Data Language• Debugging• Packages and modules (coming soon)
Features
Community Feedback
• Language enhancements• Improved adapters• New/improved cmdlets
Call To Action
Download PowerShell CTPOn non-production systems
Kick the tires and let us know what we got right/wrongLet us know about any incompatibilities with V1
Learning PowerShell
Invest and learn how to:Learn and leverage others workDiscover the systemLeverage utilitiesFormalize your work
Methods apply to V1 and V2
Learning and LeveragingIn the box documents
Release NotesGetting Started, Users Guide, Quick Reference GuideHelp
Discovery utilitiesBooksCommunityPractice ad hoc development
Utilities - Discovery
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 UtilitiesJeffrey P SnoverPartner 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 UtilitiesJeffrey P SnoverPartner Architect
Transformation and Output
Commands Functions
Format -Custom -List -Table -Wide
Convert objects into formatting records
Out -File -Host -Printer -String
Convert formatting records into output-specific directives.
Export/Import -CliXML -CSV
Converts objects into and out of file formats
ConvertTo -HTML
Converts object into other objects
Demo: Transformation and Output UtilitiesJeffrey P SnoverPartner Architect
PowerShell ScriptingInstrumentation
TextCOM.NETCmdlets
Object typesWMIXMLADOADSI
Demo: PowerShell ScriptingJeffrey P SnoverPartner Architect
Summary/Call to ActionNow available at: www.microsoft.com/downloads
Search for PowerShell
Try it, Deploy it, Use it, Share
Automate and Prosper!
Community ResourcesNewsgroup: Microsoft.Public.Windows.PowerShellTeam blog:
http://blogs.msdn.com/PowerShell/PowerShellCommunity.Org:
http://www.PowershellCommunity.OrgChannel 9
http://channel9.msdn.com/tags/PowerShellWiki
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 booksManning 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?
Complete an evaluation on CommNet and enter to win!
© 2007 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only.MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.
Scripting with COMAccess existing instrumentation
Bind to COM objects$fso = New-Object -ComObject Scripting.FileSystemObject$m = [System.Runtime.InteropServices.Marshal]$word = $m::GetActiveObject("Word.Application")
Invoke methods/access properties$fso.GetDrive(“C:”)$fso.VolumeName = “System Drive”
Understand/extend instrumentationExtend and discover properties/methods
Update-TypeData Office.Word.Types.ps1xml$fso | Get-Member
Manipulate and format resultsDefine and import custom formating
Update-FormatData Office.Word.Format.ps1xml$word.RecentFiles | Sort name | Format-Table
Allows more simpler/more powerful COM scripts because of utilities and formatting
Scripting with WMIPowerShell provides native WMI supportGet-WmiObject
Allows for inspection of WMI namespaceGet-WmiObject –list [-Namespace xx]Get-WmiObject –Class xx –Namespace xx –Property xxx – Filter xxx –ComputerName xxx –Credential xxx
Native language support[WMI] “\\JPSDESK10\root\cimv2:Win32_Process.Handle="0“[WMICLASS] "ROOT\cimv2:WIN32_PROCESS"[WMISEARCHER]"select * from Win32_process WHERE Name = 'calc.exe'"
Scripting with .NETPowerShell provides native access to any .NET classCreate any object
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")$d = New-Object System.DateTime 2006,12,25
Access Properties/Invoke Methods$d.DayOfWeek$d.AddDays(-30)
Access Statics[DateTime]::Now[DateTime]::IsLeapYear(2006)
Allows admins to easily access and leverage a huge API set because of scriptability, utilities and formatting
Scripting with XMLPowerShell provides native XML supportNative 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 TextInvoke existing tools
Existing command run directly after variables are expanded
Harvest data from existing toolsParse 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 textUse 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