ModuleXA - ICTSHOP

advertisement
Microsoft Official Course
®
Module XA
Using Windows PowerShell®
Module Overview
• Introduction to Windows PowerShell 3.0
• Windows PowerShell Remoting
• Using Windows PowerShell Cmdlets
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
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
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
Cmdlets in Windows PowerShell
•
•
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 Get-EventLog
Get-EventLog -help
Get-Help has parameters to adjust the amount of help displayed.
•
•
•
•
-detailed
-examples
-full
-online
Other cmdlets that you can use for accessing help: Update-Help,
Show-Command, Get-Command, and tab completion
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
IntelliSense
suggestions
Script pane
Console pane
Add-in
Tools pane
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
The Windows PowerShell Pipeline
•
•
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
Get-ADUser
Cmdlet
Get-ADUser –Filter *
Pipe
| Enable-ADAccount
Enable
ADAccount
Cmdlet
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
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
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)
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
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
How to Run Remote Commands
To run a remote command on a single computer:
•
•
Create a session object for a single computer using NewPSSession 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 NewPSSession 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
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
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
•
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
Group Policy Management Requirements
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
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 nonWindows PowerShell scripts.
Cmdlets for Group Policy Administration
Use Windows PowerShell to automate the management
of GPOs and the configuration of registry-based settings
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
Module Review and Takeaways
• Review Questions
• Tools
• Best Practice
• Common Issues and Troubleshooting Tips
Download