Поделиться через


Getting Started: Windows Server 2008 R2 Administration with Windows PowerShell

Applies To: Windows Server 2008 R2

Windows PowerShell™ is a command-line shell and scripting language designed especially for system administration. Built on the Microsoft .NET Framework, Windows PowerShell helps IT professionals control and automate the administration of Windows® operating systems and applications that run on Windows.

Built-in Windows PowerShell commands, called cmdlets, let you manage the computers in your enterprise from the command line. Windows PowerShell providers let you access data stores, such as the registry and certificate store, as easily as you access the file system. For more information about Windows PowerShell, see Windows PowerShell Getting Started Guide.

This document is intended for IT professionals who plan to use Windows PowerShell to manage or automate administrative tasks for Windows Server® 2008 R2. In Windows Server 2008 R2, cmdlets and providers, used for administration of a role or feature, are packaged in a module or, when parity with Windows PowerShell 1.0 is required, in a Windows PowerShell snap-in. Unlike graphical user interface administrative tools, you can combine multiple modules and snap-ins in a single Windows PowerShell session to simplify the administration of multiple roles and features. For more information about cmdlets and providers for roles and features, see What’s New in Windows PowerShell Cmdlets for Roles and Features

This document provides you with information about the typical tasks that you would need to perform and the specific steps that you would need to take to use Windows PowerShell to administer Windows Server 2008 R2. The following table maps each given task to the relevant steps in this document.

Tasks and relevant steps to administer Windows Server 2008 R2 with Windows PowerShell

Task Step

1. Install specific cmdlets to administer a specific role or feature.

  • Install role or feature-based modules and snap-ins using Server Manager

2. Start a Windows PowerShell session with all available Windows PowerShell modules and snap-ins.

  • Start a Windows PowerShell session with all the available Windows PowerShell modules and snap-ins

3. List information about the available modules, snap-ins and their associated cmdlets.

  • List all modules already imported into a Windows PowerShell session

  • List all snap-ins already added to a Windows PowerShell session

  • List all cmdlets in a module or snap-in

4. List help about the available modules, snap-ins and their associated cmdlets.

  • List cmdlet help topics for a role or feature contained in an imported module

5. Import additional modules without closing and reopening your Windows PowerShell session.

A Windows PowerShell session will not dynamically refresh to import newly installed modules after it has been started. You can perform the following steps if you have installed a new module or snap-in and do not want to close and reopen your Windows PowerShell session.

  1. Search for the newly installed module or snap-in that wish to import into your existing Windows PowerShell session.

    • List all installed modules available to be imported into a Windows PowerShell session

    • List all registered snap-ins available to be added to a Windows PowerShell session

  2. Import the desired module or snap-in into your existing Windows PowerShell session.

    • Import a single module into a Windows PowerShell session

    • Add a registered snap-in to a Windows PowerShell session

6. Review all modules or snap-ins included in Windows Server 2008 R2.

Appendix: Windows Server 2008 R2 roles and features that include Windows PowerShell cmdlets

Install role or feature-based modules and snap-ins using Server Manager

Cmdlets and providers associated with Windows PowerShell 2.0 are available after the installation of Windows Server 2008 R2. Cmdlets and providers, associated with a server role or feature that is available in Windows Server 2008 R2, are installed as part of a module or snap-in when the corresponding role or feature is installed through Server Manager. For information about Server Manager, see Adding Server Roles and Features

For a listing of modules and snap-ins available for Windows Server 2008 R2, see Appendix: Windows Server 2008 R2 roles and features that include Windows PowerShell cmdlets.

Start a Windows PowerShell session with all the available Windows PowerShell modules and snap-ins

After you have installed a role or feature that can be administered with Windows PowerShell, you must import the module or add the registered snap-in before you can use the cmdlets associated with that role or feature. You will not be able to use or view the help for cmdlets that are contained in a specific module or snap-in for a role or feature until you import the module or add the snap-in into a Windows PowerShell session.

You can import more than one module or snap-in into a single Windows PowerShell session. To simplify the administration of multiple roles and features in a single Windows PowerShell session, you can automatically import all modules and add all registered snap-ins when you start the session.

To start a Windows PowerShell session with all the available Windows PowerShell modules and snap-ins, perform the following steps.

  1. Click Start, click All Programs, click Administrative Tools, and then click Windows PowerShell Modules.

  2. If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.

List all modules already imported into a Windows PowerShell session

After you have started a Windows PowerShell session, you may want to list all modules that have been imported into the session. For example, you may want to verify that a module has already been imported into the session or find a module name to use as a parameter for a cmdlet.

To list all imported modules, type the following at the Windows PowerShell prompt, and press Enter.

Get-Module

List all snap-ins already added to a Windows PowerShell session

After you have started a Windows PowerShell session, you may want to list all snap-ins that have been added to the session. For example, you may want to verify that a snap-in has already been added to the session or find a snap-in name to use as a parameter for a cmdlet.

To list all added snap-ins, type the following at the Windows PowerShell prompt, and press Enter.

Get-PSSnapin

List all cmdlets in a module or snap-in

After you have imported modules or added snap-ins to your current Windows PowerShell session, you can determine the administrative functions that are available to you by listing the cmdlets that are supported by the module or snap-in. You can use the Get-Command cmdlet to list cmdlets that are added to your current session from an imported module or a registered snap-in.

To list all cmdlets in an imported module, type the following at the Windows PowerShell prompt, and press Enter.

Get-Command –module ModuleName

Where ModuleName refers to the name of an imported module.

For example, to list all cmdlets for Active Directory® Domain Services after you have installed the Active Directory Domain Services role and imported the ActiveDirectory module, type the following at the Windows PowerShell prompt, and press Enter.

Get-Command –module ActiveDirectory

To list all cmdlets in a registered snap-in added to your current Windows PowerShell session, type the following at the Windows PowerShell prompt, and press Enter.

Get-Command –module Snap-inName

Where Snap-inName refers to the name of a registered snap-in added to your current session.

For example, if you have installed the Windows Server Backup Features: Windows Server Backup and Command-line Tools using Server Manager and you have added the Windows.ServerBackup snap-in to a Windows PowerShell session, to list all cmdlets in the Windows.ServerBackup snap-in, type the following at the Windows PowerShell prompt, and press Enter.

Get-Command –module Windows.ServerBackup

List cmdlet help topics for a role or feature contained in an imported module

Cmdlets that are implemented for a specific role or feature for Windows Server 2008 R2 include an identifying prefix for the noun. You can list the help topics for cmdlets that support a role or feature by applying the wildcard character * and the noun prefix. The table in Appendix: Windows Server 2008 R2 roles and features that include Windows PowerShell cmdlets lists the commands to display help for all cmdlets that are implemented for a specific role or feature for Windows Server 2008 R2.

For example, Active Directory Domain Services cmdlets use “AD” to prefix the noun in cmdlet names.

To list all the help topics for Active Directory Domain Services after you have imported the ActiveDirectory module, type the following at the Windows PowerShell prompt, and press Enter.

Get-Help *AD*

List all installed modules available to be imported into a Windows PowerShell session

Before you can import a module into a Windows PowerShell session, you will need to know the name of the module.

To list all installed modules, type the following at the Windows PowerShell prompt, and press Enter.

Get-Module -ListAvailable

List all registered snap-ins available to be added to a Windows PowerShell session

Before you can add a registered snap-in to a Windows PowerShell session, you will need to know the name of the snap-in.

To list all registered snap-ins, type the following at the Windows PowerShell prompt, and then press Enter.

Get-PSSnapin -registered

For example, if you have installed the Windows Server Backup Features: Windows Server Backup and Command-line Tools using Server Manager, you can verify that the Windows.ServerBackup snap-in is installed and registered by typing the following at the Windows PowerShell prompt, and pressing Enter.

Get-PSSnapin -registered

Information about the Windows.ServerBackup snap-in will only be displayed if the snap-in was installed and registered.

Import a single module into a Windows PowerShell session

At times, you may want to import a single module into an existing Windows PowerShell session. For example, if you install a role or feature after you have started a Windows PowerShell session, the module that is associated with the newly installed role or feature will not be available until you import the module into the already started session.

To import a single module, type the following at the Windows PowerShell prompt, and then press Enter.

Import-Module ModuleName

Where ModuleName refers to the name of an available module.

For example, if you have installed the Active Directory Domain Services role, to import the ActiveDirectory module into a Windows PowerShell session, type the following at the Windows PowerShell prompt, and press Enter.

Import-Module ActiveDirectory

Add a registered snap-in to a Windows PowerShell session

A role or feature may install and register a Windows PowerShell snap-in, instead of a module, in order to remain compatible with cmdlets implemented for an earlier version of Windows PowerShell. If the cmdlets you wish to use are implemented in a snap-in, you will need to add that snap-in to make the cmdlets available for use in the current session.

To add a registered snap-in to a current Windows PowerShell session, type the following at the Windows PowerShell prompt, and then press Enter.

Add-PSSnapin Snap-inName

Where Snap-inName refers to the name of an installed and registered snap-in.

For example, if you have installed the Windows Server Backup Features: Windows Server Backup and Command-line Tools using Server Manager, you can add the Windows.ServerBackup snap-in to a Windows PowerShell session by typing the following at the Windows PowerShell prompt, and pressing Enter.

Add-PSSnapin Windows.ServerBackup

Appendix: Windows Server 2008 R2 roles and features that include Windows PowerShell cmdlets

The following table lists modules and snap-ins that support different roles and features of Windows Server 2008 R2 and suggested syntax for finding help for all cmdlets in a specific module or snap-in.

Name Required installed role or feature Command to import module or add snap-in Command to display help for role or feature cmdlets

Active Directory module for Windows PowerShell

Requires installation of the Active Directory Domain Services role

Import-Module ActiveDirectory

Get-Help *AD*

Active Directory Rights Management Services module for Windows PowerShell

No required role or feature.

Import-Module ADRMS

Get-Help *ADRMS

Active Directory Rights Management Services administration module for Windows PowerShell

Requires installation of the AD RMS role.

Import-Module ADRMSAdmin

Get-Help *-rms*

Application ID Policy Management module for Windows PowerShell

No required role or feature.

Import-Module AppLocker

Get-Help *AppLocker*

Best Practice Analyzer module for Windows PowerShell

No required role or feature.

Import-Module BestPractices

Get-Help *BPA*

Background Intelligent Transfer Service (BITS) module for Windows PowerShell

No required role or feature

Import-Module BITSTransfer

Get-Help *BITS*

counter and event cmdlets

No required role or feature.

Not a separate module or snap-in. Instead, these cmdlets are included in the core Windows PowerShell instructions.

Get-Help *counter*

Get-Help *event*

Failover Clusters module for Windows PowerShell

Requires installation of the Failover Clustering feature.

Import-Module FailoverClusters

Get-Help *Cluster*

Group Policy module for Windows PowerShell

Requires installation of the Group Policy Management feature.

Import-Module GroupPolicy

Get-Help *GP*

Network Load Balancing Clusters module for Windows PowerShell

Requires installation of the Network Load Balancing feature.

Import-Module NetworkLoadBalancingClusters

Get-Help *NLB*

Remote Desktop Services module for Windows PowerShell

Requires installation of the Remote Desktop Services role.

Import-Module RemoteDesktopServices

Get-Help *Desktop*

Server Manager module for Windows PowerShell

Does not require installation of a role or feature.

Import-module ServerManager

Get-Help *Feature*

Server Migration module for Windows PowerShell

Requires installation of the Windows Server Migration Tools feature

Add-PSSnapin Microsoft.Windows.ServerManager.Migration

Get-Help *Smig*

Troubleshooting pack support. For more information see Windows Troubleshooting Platform

Does not require installation of a role or feature.

Import-Module TroubleshootingPack

Get-Help *Troubleshoot*

Windows Backup snap-in for Windows PowerShell

Requires installation of the Windows Server Backup Features: Windows Server Backup and Command-line Tools.

Add-PSSnapin Windows.ServerBackup

Get-Help *-WB*

Internet Information Services (IIS) module for Windows PowerShell

Requires installation of the Web Server (IIS) role

Import-Module WebAdministration

Get-Help *Web*

Web Services for Management (WS-Management)

Requires installation of Web Services for Management (WS-Management) role

Add-PSSnapin Microsoft.WSMan.Management

Get-Help *WSMan*

Additional references

You can refer to the following resources for more information: