230 likes | 393 Views
How to use PowerShell in PAREXEL environment. December, 21, 2010. Bartek Bielawski Sr IT Site Services Specialist Warsaw, Poland. PART I: BASICS. What is PowerShell and how can I get it?. PowerShell IS: Automation engine Scripting language Interactive console To use it:
E N D
How to use PowerShell in PAREXEL environment December, 21, 2010 Bartek Bielawski Sr IT Site Services Specialist Warsaw, Poland
What is PowerShell and how can I get it? • PowerShell IS: • Automation engine • Scripting language • Interactive console • To use it: • Windows 7/ Windows Server 2008 R2 • Windows XP + Windows Management Framework • How pretty it can be? • PowerShell.exe – cmd.exe revisited • PowerShell ISE – notepad.exe on steroids • PowerGUI – MMC + brilliant editor (3rd party)
Hosts Demo • PowerShell.exe/ PowerShell ISE/ PowerGUI + PowerGUI editor
Switch from cmd.exe or *nix shell • Easy switch: • Cmd.exe – just launch powershell instead • Aliases/ functions to make it easier for us • *nix have their set of aliases too • ‘Old’ commands still work!
Verb-Noun to guess command • Discover: • Get-Verb + Guess Noun • Syntax almost like sentence: • Get-Process | Where { $_.WorkingSet –gt 100MB } | Stop-Process -Whatif • Meaningful parameters • disambiguate it • Tab Completion
Objects - what they are? How to use Methods How to use Parts Parts Properties Pedal Front Wheel Steer Left Back Wheel Steer Right Pedals Apply Front Brake Saddle Apply Rear Brake Frame
Objects – what they are in ‘Our’ world? How to use Methods Parts Properties Stop() DisplayName Start() Status Pause() RequiredServices Windows Service
Objects all around • PowerShell objects: • Microsoft.NET objects • COM objects • WMI Objects • AD Objects • Variables • Single ver. Array • Foreach as a key to collection • Tab to help us see interior • Methods definitions using name without ()
Pipeline Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table Common Windows PowerShell Parser Get-ProcessCmdlet Sort Cmdlet FormatCmdlet Where Cmdlet Windows PowerShell Pipeline Processor
Get-Command to know what to look for • What it can do for me? • List commands (functions, aliases, cmdlets, ‘legacy’ commands) • Show definition • Show parameters • How I can use it? • New module – what does it contain? • Bell rings – what was this cmdlet name? • I know Verbs, I know Nouns, need command!
Get-Helpask PowerShell first • Easy: My-Command -? • Basic description • Definition to know parameter names • Related links to dig more • Everything: Get-Help My-Command -full • Tons of info • Examples • Parameters descriptions • Parts: -Examples, -Parameter My-Parameter • Examples to try and learn • Parameter description to understand what I need to get my results
Get-Memberobjectsunder the lens • Too many objects • Hard to remember properties/ method names • Even harder to know how to use those • Useful to see what’s inside • Common usecases: • COM objects (Excel.Application) • To see if we got what we expected • To get static methods of .NET classes • Why? • Helps when interactive • We save our memory • Can discover not documented objects
WMI • WMI? • MS implementation of CIM • Lot of information about hardware/ software and more • Available using RPC • Why? • Inventory • Ad-hoc administration (services, processes, and God-knows-what) • How? • Get-WMIObject (alias gwmi) • Invoke-WmiMethod (alias iwmi) • -List to list, asterisk to list more… • Demo
AD • Quest – 3rd party • Very easy, very handy • Requires install on our box • Demo • MS ActiveDirectory module • Not as easy • Currently only W7 or W2k8 R2 (using RSAT)
Files, registry, event logs… • PSProviders and PSDrives • (Almost) everything is a drive • Browse registry as file system • Wonderful asterisk support • Quick ways to filter stuff • *-EventLog • Get, Limit – both local and remote • Great for quick look and decent reports • *.log • Select-string and regular expressions
What else? • VMWare • NetApp • Exchange • SharePoint • SQL • IIS • SCCM • .. And more to come! ;)
To be on the safe side… • Check it first • What if? • Please ask me to confirm… • Build from floor to roof • First get, then filter, than format/ output/ set • Check each step as you go • -WhatIf or –Confirm to avoid problems • Save good lines and reuse them later
Help! • Forums • TechNet • PowerShellCommunity.org • Twitter • Tag #PowerShell • Enjoy and learn, or opposite ;) • On your own • Free eBooks (Master PowerShell, PowerShell TFM 2nd ed, and others) • Ask PowerShell (Get-Help, -Online, F1 in PowerShell ISE) • Blogs, blogs, blogs • Podcasts (PowerScripting Podcast, Get-Scripting Podcast)