microsoft ® official course module xa using windows powershell ®

21
Microsoft ® Official Course Module XA Using Windows PowerShell ®

Upload: silvester-cain

Post on 28-Dec-2015

231 views

Category:

Documents


13 download

TRANSCRIPT

Page 1: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Microsoft® Official Course

Module XA

Using Windows PowerShell®

Page 2: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Module Overview

Introduction to Windows PowerShell 3.0

Windows PowerShell Remoting•Using Windows PowerShell Cmdlets

Page 3: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Lesson 1: Introduction to Windows PowerShell 3.0

Overview of Windows PowerShell

Enhancements in Windows PowerShell 3.0

Cmdlets in Windows PowerShell

Overview of the Windows PowerShell ISE

Demonstration: Using the Windows PowerShell ISE Editor

The Windows PowerShell Pipeline•Creating and Running Windows PowerShell Scripts

Page 4: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Overview of Windows PowerShell

• Windows PowerShell 3.0 is included with Windows 8, and supports existing scripts and command-line tools

• Cmdlets are available for performing common system and administration tasks

• The .NET framework is leveraged and provides access to thousands of objects

• An extensible interface enables enterprise developers to build custom tools and utilities to administer their software

• Windows PowerShell accepts and returns .NET objects, which can be directly manipulated or sent to other tools or databases

Page 5: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Enhancements in Windows PowerShell 3.0

• Hundreds of cmdlets

• Robust sessions

• Windows PowerShell ISE enhancements

• Transactions enable managing commands as a logical unit

• Windows PowerShell workflows

• Scheduled jobs

• Enhanced online help

• Delegated administration

• Show-Command

Page 6: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Cmdlets in Windows PowerShell

Get-Help Get-EventLog

Get-EventLog -help

• -detailed• -examples• -full• -online

• Windows PowerShell has rules for naming and implementing cmdlets.

• To access the help documentation, run Get-Help or help, followed by the cmdlet name.

Get-Help has parameters to adjust the amount of help displayed.

Other cmdlets that you can use for accessing help: Update-Help, Show-Command, Get-Command, and tab completion

Page 7: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Overview of the Windows PowerShell ISE

The ISE enables you to run commands and design, write, test, and debug scripts in a Windows GUI

Windows PowerShell tabs

Script pane

Console pane Add-in Tools pane

IntelliSensesuggestions

Page 8: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Demonstration: Using the Windows PowerShell ISE Editor

• In this demonstration, you will see how to use Windows PowerShell ISE to perform basic tasks, such as:• Moving and resizing the Console pane, and

Script pane• Showing or hiding the Script pane• Changing the text size in all panes of Windows

PowerShell ISE• Opening a script file and using IntelliSense

Page 9: Microsoft ® Official Course Module XA Using Windows PowerShell ®

The Windows PowerShell Pipeline

Get-ADUser –Filter * | Enable-ADAccount Enable ADAccount

Cmdlet

Enable ADAccount

Cmdlet

Get-ADUser Cmdlet

Get-ADUser Cmdlet

• The pipeline connects the output from one cmdlet to the input of another cmdlet

• The combination of the first cmdlet, pipe, and second cmdlet makes a pipeline

Process Object

Process Object

PipePipe

Page 10: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Creating and Running Windows PowerShell Scripts

Execution Policy restricts script execution. The execution policies include:• Restricted• AllSigned• RemoteSigned• Bypass• Unrestricted

Scripts:• Are text files with a .ps1 extension• Contain one or more PowerShell cmdlets• Require a full or relative path to execute:

• .\RunScript.ps1• E:\Demo\RunScript.ps1

Page 11: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Lesson 2: Windows PowerShell Remoting

Overview of Windows PowerShell Remoting

How Remote Commands Are Processed

Managing Windows PowerShell Remote Sessions•How to Run Remote Commands

Page 12: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Overview of Windows PowerShell Remoting

• Remoting features of Windows PowerShell are built on WinRM

• Run an individual command, or create a persistent connection or session to run a series of commands

• Remote administration also is known as remoting

• Three types of remoting:• One-to-Many (Fan-Out)• One-to-One• Many-to-One (Fan-In)

Page 13: Microsoft ® Official Course Module XA Using Windows PowerShell ®

How Remote Commands Are Processed

1. Local computer sends the Windows PowerShell command to the remote computer by using the WinRM protocol

2. Command runs in Windows PowerShell on the remote computer

3. Command results are sent back by using the WinRM protocol and appear in Windows PowerShell on the local computer

• All of the local input to a remote command is collected before any of it is sent to the remote computer

•The output is returned to the local computer as it is generated

Page 14: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Managing Windows PowerShell Remote Sessions

Two types of PowerShell remote sessions:

Create a temporary session• You can start an temporary session by using the Invoke-

Command cmdlet with the ComputerName parameter• A temporary connection is created for the command and

closes the connection when the command completes

Create a persistent session• Open a new Windows PowerShell session (PSSession) on the

remote computer, then connect to the computer and enter the session• The New-PSSession cmdlet creates the PSSession• The Invoke-Command cmdlet enables cmdlets to be run

within the PSSession• You can run as many commands as desired during the session• You must manually close the PSSession by using the Exit-

PSSession cmdlet

Page 15: Microsoft ® Official Course Module XA Using Windows PowerShell ®

How to Run Remote Commands

To run a remote command on a single computer:• Create a session object for a single computer using New-

PSSession and specifying a single computer using the ComputerName parameter.

• Use the ComputerName parameter to specify a single computer for Invoke-Command.

To run a remote command on multiple computers:• Create a session object for multiple computers using New-

PSSession and specifying a multiple computers using the ComputerName parameter.

• Use the ComputerName parameter to specify multiple computers for Invoke-Command.

To run a local script on remote computers:• Use the FilePath parameter of the Invoke-Command

cmdlet

Page 16: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Lesson 3: Using Windows PowerShell Cmdlets

Using Conditional Expressions, Loops, and Variables

What Is Windows PowerShell Eventing?

Group Policy Management Requirements•Cmdlets for Group Policy Administration

Page 17: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Using Conditional Expressions, Loops, and Variables

• A variable is a temporary holding place in memory for a value, object, or collection of objects

• Variables are named and all names are preceded by a $ character

$ADDS = Get-ADDomain

• There are a number of loop conditions:• Foreach• If• While• for

Page 18: Microsoft ® Official Course Module XA Using Windows PowerShell ®

What Is Windows PowerShell Eventing?

Eventing is the immediate notification of important actions or events

• Windows PowerShell supports eventing by listening, acting on, and forwarding management and system events

• When registering for an event through remoting, event notifications can be automatically forwarded to a central computer

• Windows PowerShell scripts can respond synchronously or asynchronously to system events

Page 19: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Group Policy Management Requirements

You can use Group Policy settings to specify whether Windows PowerShell scripts run before non-Windows PowerShell scripts during:• User computer startup and shutdown• User logon and logoff

By default, Windows PowerShell scripts run after non-Windows PowerShell scripts. 

To use Group Policy cmdlets, run one of the following:• Windows Server 2008 R2 or higher on a domain controller or on a member server that has the Group Policy Management role installed• Windows 7 or higher with RSAT installed. RSAT includes the Group Policy Management Console and its cmdlets

Page 20: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Cmdlets for Group Policy Administration

These cmdlets perform tasks for domain-based GPOs:• Maintain GPOs including GPO creation, removal, backup, and import• Associate GPOs with Active Directory containers• Set inheritance flags and permissions on Active Directory organizational units and domains• Configure registry-based policy settings and Group Policy Preferences Registry settings• Create and edit Starter GPOs

Use Windows PowerShell to automate the management of GPOs and the configuration of registry-based settings

Page 21: Microsoft ® Official Course Module XA Using Windows PowerShell ®

Module Review and Takeaways

Review Questions

Tools

Best Practice•Common Issues and Troubleshooting Tips