Windows PowerShell Basics for IT Professionals

Post on 03-Feb-2022

7 views 0 download

transcript

Windows PowerShell Basics for IT

Professionals

Peter Lammers

Lead Developer

Aeshen

Microsoft Confidential 1

What Is PowerShell?

Microsoft Confidential 2

Windows PowerShell™ includes an interactive prompt and a scripting environment

Commands are object-based

Large set of built-in commands

All shell commands use the same parser

Windows PowerShell 2.0 is installed by default on Windows Server® 2008 R2 and Windows® 7

PowerShell Syntax

Microsoft Confidential 3

Name Alias Server StorageQuota

---- ---- ------ ------------

Bob Kelly bobk smbex01 unlimited

Kim Akers kima smbex01 unlimited

PS> get-mailbox –server “smbex01”

Verb NounName

ArgumentString

Command Parameter

Property Names

Property Values

Demonstration: Getting Started with PowerShell

Microsoft Confidential 4

• PowerShell basics

• Getting help

• Windows PowerShell snap-in

• Getting cmdlet information

Piping and the Pipeline

Microsoft Confidential 5

Scenario 1Get-Service| Where-Object {$_.Status –eq “Running”}| Sort-Object Name

Cmdlet Filter Sort

Scenario 2Get-item –path HKLM:\Software\MyCompany | new-Itemproperty –name NoOfEmployees –value 8124

Demonstration: Piping, Outputting, and Formatting

Microsoft Confidential 6

• Piping and the pipeline

• Output and formatting

Data Types

Microsoft Confidential 7

Shortcut Data Type

[datetime] Date or time

[string] String of characters

[char] Single character

[double] Double-precision floating number

[single] Single-precision floating number

[int] 32-bit integer

[wmi] Windows® Management Instrumentation (WMI) instance or collection

[adsi] Active Directory® Services object

[wmiclass] WMI class

[Boolean] True or false value

Demonstration: Variables and Types

Microsoft Confidential 8

• Creating variables

• Using types

• Creating arrays

PowerShell Scripts have the .ps1 extension

PowerShell Scripts

Microsoft Confidential 9

Sample Script# This script will get files and folder stored in# C:\Scripts.$a = Get-ChildItem C:\Scripts$a

Run a ScriptC:\Scripts\MyScript.ps1& “C:\My Scripts\Test.ps1”

Demonstration: Working with Scripts

Microsoft Confidential 10

• Creating PowerShell scripts

• Running scripts

Demonstration: Automating Administrative Tasks

Microsoft Confidential 11

• Work with the Event Log

Questions and Answers

• Submit text questions using the “Ask” button

• Don’t forget to fill out the survey

• For upcoming and previously live webcasts:

www.microsoft.com/webcast

• Got webcast content ideas? Contact us at:

http://go.microsoft.com/fwlink/?LinkId=41781

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.

MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.13