windows powershell introduction 1 morgan simonsen [email protected] ementor

28
Windows PowerShell Introduction Morgan Simonsen morgan.simonsen@ementor. no Ementor

Upload: vanessa-bell

Post on 17-Jan-2016

229 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Windows PowerShell Introduction

1

Morgan Simonsen

[email protected]

Ementor

Page 2: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

What Will We Cover?

• What is Windows PowerShell?

• How does Windows PowerShell work?

• How can I use Windows PowerShell?

2

Page 3: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Level 200

Helpful Experience

• Command line experience; cmd.exe, BASH etc.

• Command line experience; parameters, output

etc.

• Scripting experience (PERL, VBScript, JScript)

etc.)

3

Page 4: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Microsoft Products Providing Windows PowerShell CmdletsMicrosoft Products Providing Windows PowerShell Cmdlets

Windows Vista

Exchange Server 2007

Operations Manager 2007

Windows Server “Longhorn”

Virtual Machine Manager

Data Protection Manager “V2”4

Page 5: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Why PowerShell?

• As companies scale-out; management

becomes very hard

• Current technologies; VBScript, WMI,

RDP

• PowerShell will provide a unified

management experience

5

Page 6: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Admin Tools Roadmap

Scenario Today Tomorrow PowerShell BenefitsGUI Shell MMC MMC with snap-

ins layered on PowerShell

GUI-Cmd parity Auto script creation (V2)

Command Shell

CMD CMD

PowerShell CMD and UNIX shell parity Command consistency Namespaces as Drives (e.g. FS, Reg, WMI, AD, Certs, etc)

Command Scripting

CMD scripting CMD scripting

PowerShell Richer language Better text utilities

COM Scripting

WSH VBScript Jscript

WSH VBScript Jscript

Jscript (.net)PowerShell

Richer language Object utilities Common access to COM, XML, .NET, ADO, WMI, ADSI

6

Page 7: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Admin Development Model

• 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

7

Page 8: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Introducing Windows PowerShell

• New Windows command-line shell

designed for system administrators

• Interactive prompt and scripting

environment

• Built on .NET Common Language

Runtime (CLR) and .NET Framework

8

Page 9: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

PowerShell Design Goals

• Ease of use

• Consisency of syntax

• Ease of learning curve

9

Page 10: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

How is PowerShell different?

• PS processes objects, not text• Large set (>100) of built in commands

with cosistent interface• Common command parser• Can run all existing utilities, tools• Multiple commands without batch files (;)

10

Page 11: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Getting and installing PowerShell

• Microsoft Download site

• x86/x64 versions available

• Installation requirements:

–Windows XP SP2, Windows Server 2003 SP1 or

later versions of Windows

–.NET Framework 2.0

11

Page 12: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Getting and installing PowerShell Continued• WinXP, W2K3 Srv: Update.exe install

• Vista/W2K8 Srv: .msu (component based install)

• Install locations:

–X86:• %systemroot%\system32\WindowsPowerShell\V1.0

–X64:• %systemroot%\system32\WindowsPowerShell\V1.0• %systemroot%\Syswow64\WindowsPowerShell\V1.0

12

Page 13: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Starting PowerShell

• Powershell.exe <parameters>–powershell -psconsolefile sqlsnapin.psc1–powershell -version 1.0 -nologo -inputformat text -outputformat XML–powershell -command {get-eventlog -logname security}–powershell -command "& {get-eventlog -logname security}”

• Start Menu

13

Page 14: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Cmdlets (Command-lets)

• Built-in, single-feature commands that manipulate

objects in PS

• Small and simple, designed to be used together with

other cmdlets (pipelining)

• Comes with built-in help (Get-Help)

• Use a Verb-Noun names (Get-Service, Set-Service)

14

Page 15: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

MSH> get-mailbox –server “smbex01”

Verb NounName

ArgumentString

Command Parameter

Cmdlets (Command-lets) Structure

Property Names

Property Values

Name Alias Server StorageQuota---- ---- ------ ------------Bob Kelly bobk smbex01 unlimitedKim Akers kima smbex01 unlimited

15

Page 16: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Cmdlet parameters

• Always identified by -, never /, -- or \

• Supports concatenation:

get-help <command> -det

• Names can be omitted:

get-help –name get-alias = get-help get-alias

16

Page 17: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Getting help in PS

• Get-Help cmdlet

• Get-Help <cmdlet>

eg. Get-Help Get-Command

eg. Get-Help Get-Command –detailed

eg. Get-Help Get-Command –full

eg. Get-Help Get-Command -examples

• Get-Help about_signing

17

Page 18: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Getting help: The 4 Pillars of Discoverability

1. Get-Command

2. Get-Help and -?

3. Get-PSDrive

4. Get-Members

18

Page 19: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Processing Objects

• PS works with .NET Objects

• .NET Objects contain:–Data

–Properties

–Methods

19

Page 20: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Learning about objects

• Get-Member: displays information

about .NET objects a cmdlet returns

get-service | get-member

20

Page 21: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Formatting Output

• PS cmdlets never format data

• Format cmdlets format data

–Format-List

–Format-Table

–Format-Custom

–Format-Wide

• Every cmdlet has default formatting based on the format

cmdlets, which you can override

21

Page 22: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Aliases

• PS has several aliases by default (dir, ls, cls, del etc)

• Display aliases:

get-alias

• Create alias:

set-alias gh Get-Help

• Delete alias:

remove-item alias:gh

22

Page 23: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Some useful cmdlets

• Get-Command• Get-Childitem• Get-ChildItemProperty• Get-Service• Get-WMIObject• Invoke-Item

23

Page 24: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Using Windows Programs

• PS can run all Windows programs

• Must be in path statement

($env:path)

• List:

Get-Command *.exe

• Aliases do not support its namesake’s paramteres

24

Page 25: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Tab Completion

• PS support Tab completions for:–Cmdlet names

–Registry paths

–Filesystem paths

–Certificate paths

25

Page 26: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Pipelining

• Cmdlets can be ”piped” together to form

complex commands

• Output from one cmdlet move along the

pipe to another cmdlet

• PS pipeline operator is | (pipe)

26

Page 27: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

For More Information

• Windows PowerShell Team blog at:

http://blogs.msdn.com/PowerShell

• Windows PowerShell ScriptCenter at:

http://www.microsoft.com/technet/scriptce

nter/hubs/msh.mspx

27

Page 28: Windows PowerShell Introduction 1 Morgan Simonsen morgan.simonsen@ementor.no Ementor

Books about PS

28