PowerShell for IT Administrators Richard Siddaway Perot Systems.
-
Upload
cynthia-oneal -
Category
Documents
-
view
216 -
download
0
Transcript of PowerShell for IT Administrators Richard Siddaway Perot Systems.
PowerShell for IT Administrators
Richard SiddawayPerot Systems
Welcome to this TechNet Event
“Pick your Own Collateral”
URL for on-line feedback is in your reminder e-mail
No Planned Fire Drills
Please turn your Mobile Phones off
To find out about future TechNet events: www.microsoft.com/uk/technetevents
The TechNet Programme
A range of tools and resources for IT ProfessionalsFREE TechNet NewsletterFREE Events and WebcastsFREE TechNet BETA Central (www.microsoft.com/uk/betacentral)
FREE Quarterly TechNet MagazineFREE comprehensive technical websiteFREE TechNet Radio, Security Centre, Learning Paths and Virtual LabsTechNet Plus – Now available for Download!
www.microsoft.com/technet
What is TechNet Plus?
The Toolkit for IT ProfessionalsTechNet Plus is an annual subscription Access to TechNet Knowledge BaseNo-limits Evaluation software for TestingBeta software available immediately2 Free Technical Support calls worth £32020% off all further Support CallsManaged Newsgroups with guaranteed answers in 24hrsNow available by Download from only £230 / year (excl VAT)For all information on TechNet Plus Subscriptions visit:
www.microsoft.com/technet/abouttn/subscriptions
Who am I?
IT Architect and systems integrator
Programming with .NET for several years
Scripting with VBScript since NT 4
VERY interested in automation
Using PowerShell since beta 2 (Monad)
Run UK PowerShell User Group
Think PowerShell is one of best pieces of technology EVER!
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
PowerShell
Next generation shell that is:As interactive and composable as BASH/KSHAs programmatic as Perl/RubyAs production oriented as AS400 CL/VMS DCLAccess data stores as easily as accessing filesystemsExtensible
SnapinsProvidersScripts
Script Types
Text.Net “interpretation” of the traditional Unix scripting model
COMWSH/VBScript style scripting
.NETManipulate any native .Net object
CommandsPowershell cmdlets emitting objects
DataTypes
Flat File – CSV etc.NETXMLWMIADSIADOADO.NETSQL
Accessing .NET
Simple scripts need [STRING] and [MATH]Advanced scripts can use any .NET objectCmdlets provide the best admin and scripting experience
.NET provides a safety net of coverage
PowerShell provides access to the entirety of the .NET Framework
SecurityInfrastructu
re
IT OperationsInfrastructu
re
Applications Infrastructu
re
Collaboration
Infrastructure
Agenda
What is PowerShell?
Learning PowerShell
Administration of windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
Learning and Leveraging
In the Box DocumentsGetting Started, Users Guide, Quick Reference GuideHelp
BooksInvest in your integrated lifetime earnings
CommunityA wise man learns from mistakes…
Practice ad hoc development
Try things out in an interactive shellStitch things together with utilitiesPut the results in a script file
Realize that the tools are unsuitable and restart with a new set of tools
Generalize (e.g., parameterize)Clean it up production-qualityIntegrate into your environmentShare with the community
Ad Hoc Development
Utilities
DiscoveryGet-Help, Get-Member, Get-Command
Object ManipulationCompare, Group, Measure, Select, Sort, Tee, Where
FormattingFormat-(Custom, List, Table, Wide)Out-(File, Host, Printer, String)Export/Import-(Clixml, CSV)ConvertTo-Html
Primary Concepts
CmdletsVerb-noun namingSpecific functionality
Pipeline.NET based objects NOT text
Help is text basedSyntax is similar to C#Data – CSV, XML, SQL WMI etc
Issues
Default install mode won’t run scriptsSet-ExecutionPolicy
No file associationCan’t automatically run scriptsCan’t double click script to run it
No remoting – yetCan use .NET and WMI
Current working directory is NOT on PATH.\myscript.ps1
Does not load all .NET assembliesUse [Reflection.Assembly]::LoadWithPartialName(" Microsoft.SqlServer.Smo ")
Learning PowerShell
Demo
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
Administering Windows
Some administrative cmdletsEventlogsServicesProcesses
WMIScripting
Administering Windows
Demo
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
PowerShell and Active Directory
NO AD support in PowerShell v1Exchange 2007 has limited AD supportQuest AD cmdlets
Currently Beta
Quest PowerGUIPowerShell Community ExtensionsScripting
Active Directory Provider
PowerShell Community ExtensionsAccess AD as “filesystem”
Navigation Use core commands
Interactive or scriptingAssociated cmdletsIssues – “open source”
Administering Active Directory
Demo
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
Exchange Management
Exchange Information no longer visible in Active Directory Users and ComputersMay need to rethink administrative tasksExchange Management Console creates, uses and shows PowerShell scripts of actionsCannot perform all actions in GUIAdministrative development model
Administrative Development
Use the GUICopy the scriptModify
Use cmdletsCreate pipelinePut into script
Exchange Management Shell
PowerShell is pre-requisite for Exchange 2007 installEMS = PowerShell + Exchange PowerShell snapin
Both coexistEMS adds 300+ cmdlets
Administering Exchange 2007
Demo
Agenda
What is PowerShell?
Learning PowerShell
Administration of Windows systems
Administration of Active Directory
Administration of Exchange 2007
Administration of SQL Server 2005
Administering non-PowerShell enabled applications
Needs a .NET APISQL Server
SharePoint
SQL Server 2005SMO = Server Management Objects
Need to use .NET
SQL Server SMO
Programmatic administration
.NET object model
Examples in C#
TasksView status
Access data
Perform backups
Administering SQL Server 2005
Demo
Summary/Call to Action
PowerShell can be used to administer large and growing parts of your environmentNow available at: www.microsoft.com/downloads
Search for PowerShell
Try it, Deploy it, Use it, Share
For More Information
User group:http://www.get-psuguk.org.uk
My Bloghttp://richardsiddaway.spaces.live.com
Get-PSUGUKUK PowerShellUser Group
Downloads
Quest AD cmdlets:http://www.quest.com/activeroles-server/arms.aspx
Quest PowerGUIhttp://www.powergui.org
PowerShell Community Extensionshttp://www.codeplex.com/Wiki/View.aspx?ProjectName=PowerShellCX
Community Resources
Newsgroup: Microsoft.Public.Windows.PowerShellTeam blog: http://blogs.msdn.com/PowerShell/Channel 9 tag: http://channel9.msdn.com/tags/PowerShellWiki: http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWikiScript Center:
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspxManning Press book by Bruce Payette: PowerShell in Action
http://manning.com/powershell/ O’Reilly book – Monad: Introducing the MSH Command Shell and Language
http://www.oreilly.com/catalog/msh/Sapien Press book by Don Jones: PowerShell
http://www.sapienpress.com/MshAnalyzer tool
http://www.karlprosser.com/coder/?cat=8
Resources
Technical Chats and Webcastshttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asp
Microsoft Learning and Certificationhttp://www.microsoft.com/learning/default.mspx
MSDN & TechNet http://microsoft.com/msdnhttp://microsoft.com/technet
Virtual Labshttp://www.microsoft.com/technet/traincert/virtuallab/rms.mspx
Newsgroupshttp://communities2.microsoft.com/communities/newsgroups/en-us/default.aspx
Technical Community Siteshttp://www.microsoft.com/communities/default.mspx
User Groupshttp://www.microsoft.com/communities/usergroups/default.mspx
Any Questions?
Thank you for attending this TechNet Event
Find these slides at:http://www.microsoft.com/uk/technetslides
Reference Slides
Scripting with COM
Access existing instrumentationBind 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 WMI
PowerShell 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 .NET
PowerShell 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 XML
PowerShell 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 Text
Invoke 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