Click to Rate and Give Feedback
TechNet
TechNet Library
Scripting
Windows Powershell

  Switch on low bandwidth view
Windows PowerShell

Updated: May 20, 2009

Applies To: Windows PowerShell 2.0

Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell™ helps IT professionals and power users control and automate the administration of the Windows operating system 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. In addition, Windows PowerShell™ has a rich expression parser and a fully developed scripting language.

Windows PowerShell™ includes the following features:

  • Cmdlets for performing common system administration tasks, such as managing the registry, services, processes, and event logs, and using Windows Management Instrumentation.

  • A task-based scripting language and support for existing scripts and command-line tools.

  • Consistent design. Because cmdlets and system data stores use common syntax and naming conventions, data can be shared easily and the output from one cmdlet can be used as the input to another cmdlet without reformatting or manipulation.

  • Simplified, command-based navigation of the operating system, which lets users navigate the registry and other data stores by using the same techniques that they use to navigate the file system.

  • Powerful object manipulation capabilities. Objects can be directly manipulated or sent to other tools or databases.

  • Extensible interface. Independent software vendors and enterprise developers can build custom tools and utilities to administer their software.

Learning Windows PowerShell

To begin learning Windows PowerShell, start with the following resources, which are included in the tool:

  • Getting Started. A brief introduction and tutorial. To open it, click Start, All Programs, Windows PowerShell 1.0, and then click Getting Started.

  • User Guide. A detailed introduction, including real-world scripts and scenarios to get you started.

  • Get-Help cmdlet. A Windows PowerShell™ cmdlet that you can use to quickly learn about the cmdlets and providers on your system. To begin, start Windows PowerShell™, and at the prompt, type:

    get-help
    To learn about the Windows PowerShell scripting language and other concepts, read the "about" topics. To see a list of "about" topics, type:

    get-help about

Related Resources

In addition to the Help available at the command line, the following resources provide more information.

Windows PowerShell Team Blog. The best resource for learning from and collaborating with other Windows PowerShell™ users. Read the Windows PowerShell Team blog, and then join the Windows PowerShell User Forum (microsoft.public.windows.powershell). Use Windows Live Search to find other Windows PowerShell blogs and resources. Then, as you develop your expertise, please freely contribute your ideas.

Windows PowerShell SDK. Provides reference content used to develop cmdlets, providers, and hosting applications.

Windows PowerShell Programmer's Guide. Provides tutorials for creating cmdlets, providers, and hosting applications. Also contains information about fundamental Windows PowerShell concepts.



Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
sample power shell      janncris ... olav_heirman   |   Edit   |   Show History
//save this as newuser.ps1

$objOU=[ADSI]"LDAP://OU=People,DC=contoso,DC=com"
$dataSource=import-csv "newusers.csv"

foreach($dataRecord in $datasource) {
#map variables to data source
$cn=$dataRecord.cn
$sAMAccountName=$dataRecord.sAMAccountName
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$displayName=$sn + ", " + $givenName
$userPrincipalName=$givenName + "." + $sn + "@contoso.com"

#create the user object
$objUser=$objOU.Create("user","CN="+$cn)
$objUser.Put("sAMAccountName",$sAMAccountName)
$objUser.Put("userPrincipalName",$userPrincipalName)
$objUser.Put("displayName",$displayName)
$objUser.Put("givenName",$givenName)
$objUser.Put("sn",$sn)
$objUser.SetInfo()
$objUser.SetPassword("C0mp!exP@ssw0rd")
$objUser.psbase.InvokeSet("AccountDisabled",$false)
$objUser.SetInfo()
}
//this code worked and the user has been added to the AD but when i run it it has some errors //in power shell


//anyone can suggest? what happened?

//save this as newusers.csv
cn,sAMAccountName,FirstName,LastName
John Woods,john.woods,Johnathan,Woods
Kim Akers,kim.akers,Kimberly,Akers




Windows PowerShell      janncris ... Thomas Lee   |   Edit   |   Show History

How you get PowerShell depends on which OS you are running:

  • Windows XP and Windows Server 2003 - PowerShell V1 and V2 versions are downloaded and installed (effectively as an OS Patch).
  • Wiindows Server 2008 - PowerShell v1 is a 'feature' and can be added. PowerShell V2 versions are downloaded and installed (effectively as an OS Patch).
  • Windows 7/Windows Server 2008 R2 - PowerShell V2 are installed by default.

See this link for more information: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx

To download PowerShell V1, see thie link: Download Windows PowerShell 1.0. The TechNet Scripting Centre has also provided a set of scripts you can start (over 500) - see: http://www.microsoft.com/technet/scriptcenter/scripts/msh/default.mspx?mfr=true.

There are other script libraries you can use including: http://www.poshcode.org, http://www.powershell.com and http://pshscripts.blogspot.com.


You can also find a PowerShell Manual at: http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/default.mspx
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker