section 6: using windows powershell to manage group policy introducing windows powershell windows...

25
Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based Logon Scripts Managing Windows Environments with Group Policy

Upload: jennifer-lawson

Post on 01-Jan-2016

309 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

Section 6: Using Windows PowerShell to Manage Group Policy

Introducing Windows PowerShellWindows PowerShell Library for

Group PolicyWindows PowerShell-Based

Logon Scripts

Managing Windows Environments with Group Policy

Page 2: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Section Objectives

After completing this section, you will be able to:Describe the Windows PowerShell featuresExplain how to perform the basic Windows PowerShell

operationsExplain how to access the Windows PowerShell library

for Group PolicyList the third-party Windows PowerShell-based logon

script tools

6-2

Page 3: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Introducing Windows PowerShell

6-3

Windows PowerShell Features

Windows PowerShell Scenarios Using Windows PowerShell

Page 4: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Windows PowerShell Features

Thousands of cmdletsScripting language to accelerate automationSupport for existing scripts and toolsStandard naming conventions for commandsAccess to ADSI, WMI, COM, ADO, HTML, and XML dataCommand-line navigation of the file system, registry,

certificate store, and moreRobust logging and error-handlingAccess to object and system administration dataExtensible interface for third-party development

6-4

Page 5: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Windows PowerShell Scenarios

Managing services, processes, registry, and WMI data

Terminal Server management

Managing IIS 7.0

Managing Group Policy

Logon Scripts

And much more!

PS C:\>

6-5

Page 6: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Using Windows PowerShell

Opening Windows PowerShell

Chaining commands

Writing Scripts

Running Scripts

Core Cmdlets

PS C:\>

6-6

Page 7: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Opening Windows PowerShell

Open Windows PowerShell in many different ways:

Run it from the Start, All Programs, Windows PowerShell, Windows PowerShell shortcut.

Type powershell at a command prompt.

Use the PowerShell taskbar shortcut.

Go to the Start screen and type PowerShell.

PS C:\>

6-6

Page 8: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Chaining Commands

You can chain several commands together on the same line such as with the following command:get-command | convertto-html -property

name,definition -title "Cmdlets" > cmdlets.htm ; invoke-item cmdlets.htm

PS C:\>

6-7

The pipe symbol sends the output of one cmdlet to

another.

The semicolon symbol signifies the beginning of a new command.

Page 9: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Writing Scripts

PowerShell scripts can be saved with a *.ps1 extension or can be written directly at the PowerShell prompt.

$a = get-service | select-object name, statusforeach ($i in $a) { if ($i.status -eq "running") {write-host $i.name -foregroundcolor "green"} elseif ($i.status -eq "stopped") {write-host $i.name -foregroundcolor "white"} else {write-host $i.name} }

6-8

After typing multiple lines of code at the prompt, press Enter twice to execute the

code block.

Page 10: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Running Scripts

By default, PowerShell does not allow scripts to be run for security reasons. The Execution Policy must be relaxed to allow scripts to run.

Use Set-ExecutionPolicy to set one of the following levels: Restricted AllSigned RemoteSigned Unrestricted Bypass

6-9

Page 11: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Core Cmdlets (1)

Add-PSSnapin Adds one or more Windows PowerShell snap-ins to the current session.

Clear-History Deletes entries from the command history.

Clear-Host Deletes entries from the command history.

Connect-PSSession Reconnects to disconnected sessions.

Disable-PSRemoting Prevents the computer from receiving remote Windows PowerShell commands.

Disable-PSSessionConfiguration

Denies access to the session configurations on the local computer.

Disconnect-PSSession Disconnects from a session.

Enable-PSRemoting Configures the computer to receive remote commands.

Enable-PSSessionConfiguration

Configures the computer to receive remote commands.

Enter-PSSession Starts an interactive session with a remote computer.

Exit-PSSession Ends an interactive session with a remote computer.

Add-PSSnapin Adds one or more Windows PowerShell snap-ins to the current session.

6-9

Page 12: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Core Cmdlets (2)

Export-Console Exports the names of snap-ins in the current session to a console file.

Export-ModuleMember Specifies the module members that are exported.

ForEach-Object Performs an operation against each of a set of input objects.

Get-Command Gets all commands.

Get-Help Displays information about Windows PowerShell cmdlets and concepts.

Get-History Gets a list of the commands entered during the current session.

Get-Job Gets Windows PowerShell background jobs (PsJobs) that are running in the current console.

Get-Module Gets the modules that have been imported, or can be imported, into the current session.

Get-PSSession Gets the Windows PowerShell sessions (PSSessions) in the current session.

Get-PSSessionConfiguration Gets the session configurations registered on the computer.

Get-PSSnapin Gets the Windows PowerShell snap-ins on the computer.

Get-Verb Gets approved Windows PowerShell verbs.

6-10

Page 13: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Core Cmdlets (3)

Import-Module Adds modules to the current session.

Invoke-Command Runs commands on local and remote computers.

Invoke-History Runs commands from the session history.

New-Module Creates a new dynamic module that exists only in memory.

New-ModuleManifest Creates a new module manifest.

New-PSSession Creates a persistent connection to a local or remote computer.

New-PSSessionConfigurationFile

Creates a file that defines a session configuration.

New-PSSessionOption Creates an object that contains advanced options for a session.

New-PSTransportOption Creates an object that contains advanced options for a session configuration.

Out-Default Sends the output to the default formatter and the default output cmdlet. It is a placeholder that lets you write your own Out-Default function or cmdlet.

Out-Host Sends output to the console.

Out-Null Deletes output instead of sending it to the console.

6-10

Page 14: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Core Cmdlets (4)

Receive-Job Gets the results of the Windows PowerShell background jobs in the current session.

Register-PSSessionConfiguration

Creates and registers a new session configuration.

Remove-Job Deletes a Windows PowerShell background job.

Remove-Module Removes modules from the current session.

Remove-PSSession Closes one or more Windows PowerShell sessions (PSSessions).

Remove-PSSnapin Removes Windows PowerShell snap-ins from the current session.

Resume-Job Restarts a suspended job.

Save-Help Downloads and saves the newest help files to a file system directory.

Set-PSDebug Turns script debugging features on and off, sets the trace level and toggles strict mode.

Set-PSSessionConfiguration Changes the properties of a registered session configuration.

Set-StrictMode Establishes and enforces coding rules in expressions, scripts, and script blocks.

Start-Job Starts a Windows PowerShell background job.

6-11

Page 15: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Core Cmdlets (5)

Receive-Job Gets the results of the Windows PowerShell background jobs in the current session.

Register-PSSessionConfiguration Creates and registers a new session configuration.

Remove-Job Deletes a Windows PowerShell background job.

Remove-Module Removes modules from the current session.

Remove-PSSession Closes one or more Windows PowerShell sessions (PSSessions).

Remove-PSSnapin Removes Windows PowerShell snap-ins from the current session.

Resume-Job Restarts a suspended job.

Save-Help Downloads and saves the newest help files to a file system directory.

6-11/12

Stop-Job Stops a Windows PowerShell background job.

Suspend-Job Temporarily stops workflow jobs.

Test-ModuleManifest Verifies that a module manifest accurately describes the contents of a module.

Test-PSSessionConfigurationFile

Verifies the keys and values in a session configuration file.

Unregister-PSSessionConfiguration

Deletes a registered session configurations from the computer.

Update-Help Downloads and installs the newest help files on your computer.

Wait-Job Suppresses the command prompt until one or all of the Windows PowerShell background jobs are complete.

Where-Object Creates a filter that controls which objects will be passed along a command pipeline.

Page 16: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Windows PowerShell Library for Group Policy

A Windows PowerShell library for Group Policy is now available.

import-module grouppolicy

get-command -module grouppolicy

6-13

Page 17: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Windows PowerShell Cmdlets for Group Policy

6-13

Invoke-GPUpdate Get-GPPermissions Remove-GPRegistryValue

Get-GPResultantSetOfPolicy Set-GPPermissions Rename-GPO

Backup-GPO Import-GPO Restore-GPO

New-GPO Copy-GPO Set-GPInheritance

New-GPLink Get-GPPermission Set-GPLink

Get-GPO Get-GPInheritance Set-GPPermission

Get-GPOReport New-GPStarterGPO Set-GPPrefRegistryValue

Get-GPStarterGPO Remove-GPLink Set-GPRegistryValue

Get-GPPrefRegistryValue Remove-GPO

Get-GPRegistryValue Remove-GPPrefRegistryValue

Below are the CmdLets specific to Group Policy:

Page 18: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Windows PowerShell-Based Logon Scripts

Windows 7 and later allow for Windows PowerShell-based logon scripts.

Windows PowerShell is enabled by default in Windows 7 and Windows Server 2008 R2.

Windows PowerShell Logon Scripts allow for more powerful logon scripts.

Use PowerShell ISE to create and edit scriptsOther third-party editing tools include:

Specops Command (http://www.specopssoft.com) Admin Script Editor (ASE) (http://adminscripteditor.com) PowerGUI (http://www.powergui.org)

6-14

Page 19: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Summary

Some of the Windows PowerShell features are:Cmdlets for performing administrative tasksScripting language that accelerates automation of

repetitive tasks due to its integration with the command-line shell

Support for existing scripts, existing command-line tools, and multiple operating systems

Commands that follow standard naming conventions and work with a small set of intuitive utilities

6-16

Page 20: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Summary (cont.)

Simple access to objects and system administration data, and the ability to pipe objects between command-line tools

Extensible interface that allows third-party vendors to quickly build custom tools and utilities to administer applications running Windows Server 2008

6-16

Page 21: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Summary (cont.)

You should know how to perform some of the following basic

Windows PowerShell tasks: Open Windows PowerShell: Three different methods: 1) Click Start,

All Programs, Windows PowerShell, and Windows PowerShell

shortcut. 2) Type powershell at the command prompt. 3) Click Start,

select Run, and type powershell.

Chain commands: Chain several commands together on the

same line.

Write scripts: Compose scripts at the command-line within the

Windows PowerShell.

Run scripts: Type the full path to the file, or, if the current directory

is where the scripts are located, type .\ before the

file name.

6-16

Page 22: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Summary (cont.)

To access the Windows PowerShell library for Group Policy, first load the Group Policy module (open Windows PowerShell and type import-module grouppolicy). To display the list of Group Policy commands, open Windows PowerShell and type get-command -module grouppolicy.

Some of the third-party Windows PowerShell-based logon script tools are:

Specops command Admin Scipt Editor PowerGUI

6-16

Page 23: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Knowledge Check

1. What must you do in Windows PowerShell before you can display the list of Group Policy commands?Load the Group Policy module

6-17

Page 24: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Knowledge Check (cont.)

2. Which of the following is a feature of Windows PowerShell? a. Simple access to objects and system

administration data, and provides the ability to pipe objects between command-line tools

b. Cmdlets for performing administrative tasks

c. Run PowerShell commands against Windows 2000 operating systems

d. Logging and error-handling capabilities for script execution tracking and error handling

6-17

Page 25: Section 6: Using Windows PowerShell to Manage Group Policy Introducing Windows PowerShell Windows PowerShell Library for Group Policy Windows PowerShell-Based

© 2013 Global Knowledge Training LLC. All rights reserved.

Knowledge Check (cont.)

3. Which extension is used to save a Windows PowerShell script file?.ps1

4. List some of the third-party Windows PowerShell-based logon script tools.Specops command

Admin Scipt Editor

PowerGUI

6-17