PowerShell Richard Siddaway Perot Systems

31 Slides1.41 MB

PowerShell Richard Siddaway Perot Systems

Welcome to this TechNet Event “Pick your Own Collateral” URL for on-line feedback is in your e-mail reminder 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 Professionals FREE TechNet Newsletter FREE Events and Webcasts FREE TechNet BETA Central (www.microsoft.com/uk/betacentral) FREE Quarterly TechNet Magazine FREE comprehensive technical website FREE TechNet Radio, Security Centre, Learning Paths and Virtual Labs TechNet Plus – Now available for Download! www.microsoft.com/technet

What is TechNet Plus? The Toolkit for IT Professionals TechNet Plus is an annual subscription Access to TechNet Knowledge Base No-limits Evaluation software for Testing Beta software available immediately 2 Free Technical Support calls worth 320 20% off all further Support Calls Managed Newsgroups with guaranteed answers in 24hrs Now available by Download from only 230 / year (excl VAT) For all information on TechNet Plus Subscriptions visit: www.microsoft.com/technet/abouttn/subscriptions

Security Infrastructu re IT Operations Infrastructu re Applications Infrastructu re Collaboratio n Infrastructu re

Learning to Fish Invest and learn how to: Learn and leverage others work Discover the system Leverage utilities Formalize your work

Learning and Leveraging In the Box Documents Getting Started, Users Guide, Quick Reference Guide Help Books Invest in your integrated lifetime earnings Community A wise man learns from mistakes Practice ad hoc development

Ad Hoc Development Try things out in an interactive shell Stitch things together with utilities Put 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-quality Integrate into your environment Share with the community

Utilities Discovery Get-Help, Get-Member, Get-Command Object Manipulation Compare, Group, Measure, Select, Sort, Tee, Where Formatting Format-(Custom, List, Table, Wide) Out-(File, Host, Printer, String) Export/Import-(Clixml, CSV) ConvertTo-Html

demo Learning to Fish

Accessing .NET Simple scripters need [STRING] and [MATH] Advanced scripters get any .Net object they want Cmdlets provide the best admin and scripting experience .NET provides a safety net of coverage PowerShell provides access to the entirety of the .NET Frameworks

Accessing .NET Creating .Net objects d New-Object System.DateTime 2005,4,20 [DateTime] “4-20-2005” Parse(), Constructor, Converter Inspecting properties-methods d Get-Member d Get-Member –Static Accessing properties-methods Instance d.DayOfWeek d.AddMonths(6) Static [DateTime]::Now [DateTime]::IsLeapYear(2005) Method matching is done via least-type differencing Use casts to override [DateTime]::IsLeapYear([INT] x)

demo Accessing .NET

PowerShell Community Extensions Snapin containing additional cmdlets Active Directory Provider Access AD as if it was the file system Dir through Active Directory Where do I get the Extensions? http://www.codeplex.com/Wiki/View.aspx?ProjectN ame PowerShellCX

PowerShell CMDLETS for Active Directory What is ActiveRoles Management Pack for PowerShell? PowerShell CMDLETS for managing Active Directory or Active Directory through Quest ActiveRoles Server What do the CMDLETS cost? The CMDLETS are free Where do I get the Management Pack? http://www.quest.com/activeroles server/ or http://www.PowerGUI.org/

PowerShell CMDLETS for Active Directory with ActiveRoles Server Active Directory or ADAM Domain Controller Microsoft Power Shell -proxy switch Quest ActiveRoles Server Provisioning and Management for Active Directory, ADAM and beyond Automated User & Group Management ActiveRoles Roles Policies Applications Databases Home Folders CMDLETS work directly with Active Directory or via the ActiveRoles Server proxy Approval Workflow Virtual Schema Exchange Mailboxes

PowerGUI and the PowerGUI.Org Community What is PowerGUI? Graphical Administrative Console for PowerShell What does PowerGUI cost? The PowerGUI application is free Where Can I get PowerGUI? http://www.PowerGUI.org

PowerGUI and the PowerGUI.Org Community Visit PowerGUI.org today Download the PowerGUI Application Download PowerShell CMDLETS Share your own PowerShell CMDLETS Gain or Share PowerShell Expertise

demo Managing Active Directory

Summary/Call to Action Powershell can be used to administer large and growing parts of your environment Now 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 Blog http://richardsiddaway.spaces.live.com PowerShell for IT Admins May 22 https://msevents.microsoft.com/cui/EventDe tail.aspx?culture en-GB&eventid 10323349 34

Community Resources Newsgroup: Microsoft.Public.Windows.PowerShell Team blog: http://blogs.msdn.com/PowerShell/ Channel 9 tag: http://channel9.msdn.com/tags/PowerShell OMark van Orsouw’s blog: http://ThePowerShellGuy.Com Wiki: http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShell Wiki Script Center: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx Manning 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 Webcasts http://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asp Microsoft Learning and Certification http://www.microsoft.com/learning/default.mspx MSDN & TechNet http://microsoft.com/msdn http://microsoft.com/technet Virtual Labs http://www.microsoft.com/technet/traincert/virtuallab/rms.mspx Newsgroups http://communities2.microsoft.com/ communities/newsgroups/en-us/default.aspx Technical Community Sites http://www.microsoft.com/communities/default.mspx

Any Questions? [email protected]

Thank you for attending this TechNet Event Find these slides at: http://www.microsoft.com/uk/technetslides

Reference Slides

Scripting with COM Access 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 instrumentation Extend and discover properties/methods Update-TypeData Office.Word.Types.ps1xml fso Get-Member Manipulate and format results Define 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 support Get-WmiObject Allows for inspection of WMI namespace Get-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 class Create any object [reflection.assembly]::LoadWithPartialName("System.Wind ows.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 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

Back to top button