powershell for dummies

22
PowerShell for Dummies Kurt Callemin

Upload: feryal

Post on 23-Feb-2016

50 views

Category:

Documents


1 download

DESCRIPTION

PowerShell for Dummies. Kurt Callemin. WHO AM I ?. Kurt Callemin Final year student at KHBO: Master of Science Electronics- ICT Microsoft Student Partner since 2009 Developer Blog: http://www.ckurt.net Yelper: http://www.yelper.be/C_Kurt Twitter: C_Kurt. AGENDA. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: PowerShell for Dummies

PowerShell for DummiesKurt Callemin

Page 2: PowerShell for Dummies

WHO AM I ?

• Kurt Callemin• Final year student at KHBO: Master of Science Electronics- ICT• Microsoft Student Partner since 2009• Developer

• Blog: http://www.ckurt.net • Yelper: http://www.yelper.be/C_Kurt• Twitter: C_Kurt

2

Page 3: PowerShell for Dummies

AGENDA

• Introduction to PowerShell• Learn to investigate and explore PowerShell• Drill into utilities cmdlets

3

Page 4: PowerShell for Dummies

WINDOWS POWERSHELL

4

• New command line and scripting language

• Interactive and Composable• Programmatic• Production Oriented

Page 5: PowerShell for Dummies

PRODUCTIVITY

5

Exchange 2003 (VBScript) Exchange 2007

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

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”

Page 6: PowerShell for Dummies

DEMO 1Short Introduction

6

Page 7: PowerShell for Dummies

OBJECTS

PartsProperties

Front Wheel

Back Wheel

Pedals

Saddle

Frame

How to useMethods

Pedal

Steer Left

Steer Right

Apply Front Brake

Apply Rear Brake

Parts How to use

“An object is a collection of parts and how to use them”

7

Page 8: PowerShell for Dummies

OBJECTS

DisplayName

PartsProperties

Status

RequiredServices

Stop()

How to useMethods

Start()

Pause()

WindowsService

8

Page 9: PowerShell for Dummies

ARRAYS

• Data structure that holds other objects• Each object in its own compartment• Access compartments using []

$Processes = Get-Process

$Processes[0].name $Processes[4].name

ObjectObject Object Object Object

9

Page 10: PowerShell for Dummies

THE KIND OF OBJECTS

Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table

Get-ProcessCm

dlet

Common Windows PowerShell Parser

Windows PowerShell Pipeline ProcessorW

here Cmdlet

Sort Cm

dlet

Format

Cmdlet

10

Page 11: PowerShell for Dummies

DEMO 2Working with Objects

11

Page 12: PowerShell for Dummies

LEARN AND LEVERAGE

• In the box documents• PowerShell_ISE Help• Getting Started• User’s Guide• About Help• Cmdlet Help • Provider Help

• Discovery utilities• Books• Community• Practice ad hoc development

12

Page 13: PowerShell for Dummies

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

Get-Module Shows packages of commands

13

Page 14: PowerShell for Dummies

DEMO 3Discovery Utilities

14

Page 15: PowerShell for Dummies

Utilities – Object Manipulation

Command ActionCompare Compare 2 sets of objectsForeach Act on each element of a setGroup Split a set of objects into groupsMeasure Measure some property of a set of objectsSelect Select a set of properties from a set of objectsSort Sort objectsTee Make a copy of a set of objectsWhere Select a subset of objects

15

Page 16: PowerShell for Dummies

DEMO 4Object Manipulation Utilities

16

Page 17: PowerShell for Dummies

TRANSFORMATION and OUTPUTCommands Functions

Format -Custom -List -Table -Wide

Convert objects into formatting records

Out -File -GridView -Host -Printer -String

Convert formatting records into output-specific directives.

Export/Import -CliXML -CSV

Converts objects into and out of file formats

ConvertTo -CSV -HTML -XML

Converts object into other objects

17

Page 18: PowerShell for Dummies

DEMO 5Transformation and Output Utilities

18

Page 19: PowerShell for Dummies

Summary

• Now available at: www.microsoft.com/downloads• Search for PowerShell

• Try it, Deploy it, Use it, Share

• More Sessions: Scripting• http://www.msteched.com/2010/NorthAmerica/WSV401• http://www.msteched.com/2010/NorthAmerica/OSP402

19

Page 20: PowerShell for Dummies

POWERSHELL COMMUNITY

• Newsgroup: Microsoft.Public.Windows.PowerShell• Team blog: http://blogs.msdn.com/PowerShell/• PowerShellCommunity.Org: http://www.PowershellCommunity.Org• Channel 9 http://channel9.msdn.com/tags/PowerShell• Wiki

• 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 books

• Manning 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

20

Page 21: PowerShell for Dummies

Thank you!Please fill out session evaluations

21