windows powershell introduction 1 morgan simonsen [email protected] ementor
TRANSCRIPT
What Will We Cover?
• What is Windows PowerShell?
• How does Windows PowerShell work?
• How can I use Windows PowerShell?
2
Level 200
Helpful Experience
• Command line experience; cmd.exe, BASH etc.
• Command line experience; parameters, output
etc.
• Scripting experience (PERL, VBScript, JScript)
etc.)
3
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
Why PowerShell?
• As companies scale-out; management
becomes very hard
• Current technologies; VBScript, WMI,
RDP
• PowerShell will provide a unified
management experience
5
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
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
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
PowerShell Design Goals
• Ease of use
• Consisency of syntax
• Ease of learning curve
9
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
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
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
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
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
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
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
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
Getting help: The 4 Pillars of Discoverability
1. Get-Command
2. Get-Help and -?
3. Get-PSDrive
4. Get-Members
18
Processing Objects
• PS works with .NET Objects
• .NET Objects contain:–Data
–Properties
–Methods
19
Learning about objects
• Get-Member: displays information
about .NET objects a cmdlet returns
get-service | get-member
20
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
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
Some useful cmdlets
• Get-Command• Get-Childitem• Get-ChildItemProperty• Get-Service• Get-WMIObject• Invoke-Item
23
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
Tab Completion
• PS support Tab completions for:–Cmdlet names
–Registry paths
–Filesystem paths
–Certificate paths
25
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
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
Books about PS
28