Active Directory (PowerShell)

From vwiki
Revision as of 21:15, 15 April 2013 by Sstrutt (talk | contribs) (Initial creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Getting Started

You need to have RSAT (Remote Server Administration Tools) installed For Windows 7 see - http://www.microsoft.com/en-gb/download/details.aspx?id=7887. This enables your local machine to remotely manage Windows Servers and Services via the usual MMC GUI's (eg AD Users and Computers) and (most importantly) includes PowerShell modules in order to be able to do so as well.

Be aware that PowerShell DFS management is currently poor, its only possible from Windows 8 and 2012 machines, and even then its very limited.

Once installed go to Control Panel | Programs | Turn Windows features on or off and enable the PowerShell module, full path as follows...

  • Remote Server Administration Tools | Role Administration Tools | Active Directory Module for Windows PowerShell

In order to be able access the PowerShell Active Directory CmdLets, import the AD module into your PowerShell session...

Import-Module ActiveDirectory

Group Policy

The PowerShell GPO module is installed with

In order to be able access the PowerShell GPO CmdLets, import the GPO module into your PowerShell session...

Import-Module GroupPolicy

Users

Get-Users examples

$users = Get-ADUser -Filter * -SearchBase "DC=domain,DC=com"                           # Get all users in domain.com
$user = Get-ADUser -Filter {SamAccountName -eq "username"}                             # Get user by logon/SAM account name
$user = Get-ADUser -Filter {SamAccountName -eq "username"} -Properties *               # Get all properties for user
$user = Get-ADUser -Filter {{Surname -eq "last" -and GivenName -eq "first"}}           # Get user by first and last names
$users = Get-ADUser -Filter * -SearchBase "OU=London,OU=Users,DC=EU,DC=domain,DC=com"  # Get users in London OU

Errors

Command Examples

Managing Multiple Domains

Unless you've specified otherwise, commands will be handled by the domain identified by ...?

Use -Server and -Credentials options, available for all PowerShell AD commands, to specify the DC and credentials required to service the commands.