SlideShare a Scribd company logo
Windows PowerShell – Connect to Active Directory
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To..................................................................................................................................................1
Pre-Requisites ...........................................................................................................................................1
Current Execution Policy...........................................................................................................................2
PowerShell Script – Connect AD ...................................................................................................................2
Code Snippet – Connect to AD..................................................................................................................2
PowerShell Execution – Connect Active Directory (AD) .......................................................................3
PowerShell Output – Key-In Authentication Information.....................................................................3
PowerShell Output – List AD User Attribute.........................................................................................4
PowerShell Output – List AD User Attribute.........................................................................................4
Windows PowerShell – Connect to Active Directory
1 | P a g e
Overview
In this guide we will demonstrate, establishing connection to active directory, this script could be run on
local active directory or remote AD server.
Applies To
Tested on Windows 10, Windows 2008 R2 and Windows 2012.
Pre-Requisites
1) Active Directory should be installed and configured on the server.
2) Access to Active Directory for the user is needed.
3) Firewall should be configured to enable traffic for port 839 on the AD Server.
4) Launch PowerShell Command Console or PowerShell ISE.
To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or
“Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”.
Each Execution Policy type and its purpose is shown in the below table.
Policy Type Purpose
Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode.
AllSigned Only scripts signed by a trusted publisher can be run.
RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run.
Unrestricted No restrictions; all Windows PowerShell scripts can be run.
Windows PowerShell – Connect to Active Directory
2 | P a g e
Current Execution Policy
To know the current run the PowerShell cmdlet; Get-ExecutionPolicy
To list execution policies that can be configured run the PowerShell cmdlet; Get-ExecutionPolicy -List
PowerShell Script – Connect AD
In this PowerShell script we will demonstrate only AD connection and list of user, when credentials is
issued and connection to AD is successful, “administrator” account attributes will be listed.
Code Snippet – Connect to AD
This code snippet is for demonstrating “Connecting to Active Directory ”.
Clear-Host
Set-Location $env:USERPROFILE
Push-Location $env:USERPROFILE
#
# Import Active Directory Module
#
Import-Module ActiveDirectory
Windows PowerShell – Connect to Active Directory
3 | P a g e
#
# Set PS Provider - Active Directory
#
$ADConnection=New-PSDrive -Name ADDrive -PSProvider ActiveDirectory -Root "DC=ftech,DC=com" -
Server f1ind.ftech.com:389 -Credential "ftechvcp.muthukrishna" -ErrorAction Ignore
if ($ADConnection.Name -eq 'ADDrive') {
if ($ADConnection.Name -eq 'ADDrive') {
[System.Console]::Beep(600,500)
Write-host "Connected to Active Directory" -BackgroundColor Black -ForegroundColor Green
}
Set-Location ADDrive:
Get-ADuser administrator
Set-Location c:
Push-Location c:
Remove-PSDrive -Name ADDrive
} else {
Write-host "`nUnable to Connect to Active Directory" -BackgroundColor Black -ForegroundColor Red
[System.Console]::Beep(600,500)
}
PowerShell Execution – Connect Active Directory (AD)
When script is executed; the script will ask for credentials and connect to Active Directory is established
when the user’s credentials are correct.
This script will only list the user after connecting to Active Directory and list user’s attributes, however
this script will not check or validate if the user exists or not.
PowerShell Output – Key-In Authentication Information
When the script is executed user has to key-In the username and password, who has access to active
directory.
Windows PowerShell – Connect to Active Directory
4 | P a g e
PowerShell Output – List AD User Attribute
When script is executed; once successfully establishing the connection with Active Directory, script will
query and list active directory user’s attributes are listed.
PowerShell Output – List AD User Attribute
In this output the active directory user’s attributes are listed and the user belongs to a different
Organization Unit (OU). In this example in the script we have modified the user to be connected and
queried.

More Related Content

What's hot (20)

PDF
Mcqs first year physics notes
Usman Mustafvi
 
PPT
Trigonometria no Triângulo Retângulo
Érica Alves
 
PDF
TEOREMA DE PITÁGORAS
Cristiano Alves
 
PDF
Employer Branding
Fernando Domingues
 
DOC
âNgulos
Docas Vivas
 
DOC
Exercícios teorema pitagoras
Michele Boulanger
 
DOCX
Projeto de Recursos Humanos
Cíntia Torres da S de Souza
 
PDF
Geometria Espacial
neliosnahum
 
PPTX
Gestão de pessoas e o papel do RH
Thiago Santos
 
PDF
ITI COPA Python MCQ Most Important New Question
SONU HEETSON
 
PDF
Estatistica resumida
Anderson Hoot
 
PDF
Exercicio de geometria analitica
Estude Mais
 
PDF
A Importância da Comunicação Interna
Fabio Mincarelli Monfrin
 
PDF
RRB ALP CBT 2 Electronics Mechanic Question Paper MCQ.pdf
SONU HEETSON
 
PPT
Volumes
rukka
 
PPT
Arcos congruos
Edgar Ribeiro
 
PDF
Questões de estatística - Enem e Enade (com resoluções) - Prof MSc Uanderson ...
Prof MSc Uanderson Rebula
 
PPT
Planejamento Estrategico Pessoal
Lauro Jorge Prado
 
PDF
Expressões numéricas com potências
Rita Sousa
 
Mcqs first year physics notes
Usman Mustafvi
 
Trigonometria no Triângulo Retângulo
Érica Alves
 
TEOREMA DE PITÁGORAS
Cristiano Alves
 
Employer Branding
Fernando Domingues
 
âNgulos
Docas Vivas
 
Exercícios teorema pitagoras
Michele Boulanger
 
Projeto de Recursos Humanos
Cíntia Torres da S de Souza
 
Geometria Espacial
neliosnahum
 
Gestão de pessoas e o papel do RH
Thiago Santos
 
ITI COPA Python MCQ Most Important New Question
SONU HEETSON
 
Estatistica resumida
Anderson Hoot
 
Exercicio de geometria analitica
Estude Mais
 
A Importância da Comunicação Interna
Fabio Mincarelli Monfrin
 
RRB ALP CBT 2 Electronics Mechanic Question Paper MCQ.pdf
SONU HEETSON
 
Volumes
rukka
 
Arcos congruos
Edgar Ribeiro
 
Questões de estatística - Enem e Enade (com resoluções) - Prof MSc Uanderson ...
Prof MSc Uanderson Rebula
 
Planejamento Estrategico Pessoal
Lauro Jorge Prado
 
Expressões numéricas com potências
Rita Sousa
 

Similar to How To Connect To Active Directory PowerShell (20)

PDF
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
PPT
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
PPTX
PowerShell for Cyber Warriors - Bsides Knoxville 2016
Russel Van Tuyl
 
PDF
AD Cmdlets
Brian McCann
 
PDF
I Have the Power(View)
Will Schroeder
 
PPTX
An Introduction to PowerShell for Security Assessments
EnclaveSecurity
 
PPTX
Using PowerShell for active directory management
Ravikanth Chaganti
 
PPTX
CCI2019 - I've got the Power! I've got the Shell!
walk2talk srl
 
PPTX
Mark Minasi What’S New In Active Directory For Windows 7 Server 2008 R2
Nathan Winters
 
PPT
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
PPTX
Automating AD Domain Services Administration
Napoleon NV
 
PPT
Automating ad with powershell
Concentrated Technology
 
PPTX
Windows PowerShell.pptx
MuhammadYasirKhan42
 
PPTX
An Introduction to PowerShell for Security Assessments
EnclaveSecurity
 
PPTX
Microsoft Offical Course 20410C_04
gameaxt
 
PPTX
Post exploitation using powershell
Mihir Shah
 
PPTX
Incorporating PowerShell into your Arsenal with PS>Attack
jaredhaight
 
PPTX
Windows power shell basics
Dan Morrill
 
PPTX
IT security : Keep calm and monitor PowerShell
ManageEngine
 
PPSX
Sunil phani's take on windows powershell
Sunil Phani
 
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 
PowerShell for Cyber Warriors - Bsides Knoxville 2016
Russel Van Tuyl
 
AD Cmdlets
Brian McCann
 
I Have the Power(View)
Will Schroeder
 
An Introduction to PowerShell for Security Assessments
EnclaveSecurity
 
Using PowerShell for active directory management
Ravikanth Chaganti
 
CCI2019 - I've got the Power! I've got the Shell!
walk2talk srl
 
Mark Minasi What’S New In Active Directory For Windows 7 Server 2008 R2
Nathan Winters
 
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 
Automating AD Domain Services Administration
Napoleon NV
 
Automating ad with powershell
Concentrated Technology
 
Windows PowerShell.pptx
MuhammadYasirKhan42
 
An Introduction to PowerShell for Security Assessments
EnclaveSecurity
 
Microsoft Offical Course 20410C_04
gameaxt
 
Post exploitation using powershell
Mihir Shah
 
Incorporating PowerShell into your Arsenal with PS>Attack
jaredhaight
 
Windows power shell basics
Dan Morrill
 
IT security : Keep calm and monitor PowerShell
ManageEngine
 
Sunil phani's take on windows powershell
Sunil Phani
 
Ad

More from VCP Muthukrishna (20)

PDF
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
PDF
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
PDF
How To List Files and Display In HTML Format
VCP Muthukrishna
 
PDF
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
PDF
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
PDF
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
PDF
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
PDF
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
PDF
How To List Nginx Modules Installed / Complied on CentOS 7
VCP Muthukrishna
 
PDF
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
PDF
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
PDF
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
PDF
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
PDF
How To Create PowerShell Function
VCP Muthukrishna
 
PDF
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
PDF
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
PDF
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
PDF
Nginx bind() to 0.0.0.0:9080 failed
VCP Muthukrishna
 
PDF
How To Install and Configure Screen on CentOS 7
VCP Muthukrishna
 
How to Fix Duplicate Packages in YUM on CentOS 7
VCP Muthukrishna
 
How To Install and Configure GNome on CentOS 7
VCP Muthukrishna
 
How To List Files on Remote Server - PowerShell
VCP Muthukrishna
 
How To List Files and Display In HTML Format
VCP Muthukrishna
 
How To Check and Delete a File via PowerShell
VCP Muthukrishna
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
VCP Muthukrishna
 
How To Setup SSH Keys on CentOS 7
VCP Muthukrishna
 
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
Windows PowerShell Basics - How To List PSDrive Info
VCP Muthukrishna
 
How To List Nginx Modules Installed / Complied on CentOS 7
VCP Muthukrishna
 
Windows PowerShell Basics – How To Create powershell for loop
VCP Muthukrishna
 
How To Construct IF and Else Conditional Statements
VCP Muthukrishna
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
VCP Muthukrishna
 
How To Create Power Shell Function Mandatory Parameter Value
VCP Muthukrishna
 
How To Create PowerShell Function
VCP Muthukrishna
 
How To Disable IE Enhanced Security Windows PowerShell
VCP Muthukrishna
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
How To Configure Nginx Load Balancer on CentOS 7
VCP Muthukrishna
 
Nginx bind() to 0.0.0.0:9080 failed
VCP Muthukrishna
 
How To Install and Configure Screen on CentOS 7
VCP Muthukrishna
 
Ad

Recently uploaded (20)

PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Biography of Daniel Podor.pdf
Daniel Podor
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 

How To Connect To Active Directory PowerShell

  • 1. Windows PowerShell – Connect to Active Directory i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To..................................................................................................................................................1 Pre-Requisites ...........................................................................................................................................1 Current Execution Policy...........................................................................................................................2 PowerShell Script – Connect AD ...................................................................................................................2 Code Snippet – Connect to AD..................................................................................................................2 PowerShell Execution – Connect Active Directory (AD) .......................................................................3 PowerShell Output – Key-In Authentication Information.....................................................................3 PowerShell Output – List AD User Attribute.........................................................................................4 PowerShell Output – List AD User Attribute.........................................................................................4
  • 2. Windows PowerShell – Connect to Active Directory 1 | P a g e Overview In this guide we will demonstrate, establishing connection to active directory, this script could be run on local active directory or remote AD server. Applies To Tested on Windows 10, Windows 2008 R2 and Windows 2012. Pre-Requisites 1) Active Directory should be installed and configured on the server. 2) Access to Active Directory for the user is needed. 3) Firewall should be configured to enable traffic for port 839 on the AD Server. 4) Launch PowerShell Command Console or PowerShell ISE. To run this script, Execution Policy should be set to either of these “AllSigned” or “RemoteSigned” or “Unrestricted”, you can get current execution policy by running the command; “Get-ExecutionPolicy”. Each Execution Policy type and its purpose is shown in the below table. Policy Type Purpose Restricted No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned Only scripts signed by a trusted publisher can be run. RemoteSigned Downloaded scripts must be signed by a trusted publisher before they can be run. Unrestricted No restrictions; all Windows PowerShell scripts can be run.
  • 3. Windows PowerShell – Connect to Active Directory 2 | P a g e Current Execution Policy To know the current run the PowerShell cmdlet; Get-ExecutionPolicy To list execution policies that can be configured run the PowerShell cmdlet; Get-ExecutionPolicy -List PowerShell Script – Connect AD In this PowerShell script we will demonstrate only AD connection and list of user, when credentials is issued and connection to AD is successful, “administrator” account attributes will be listed. Code Snippet – Connect to AD This code snippet is for demonstrating “Connecting to Active Directory ”. Clear-Host Set-Location $env:USERPROFILE Push-Location $env:USERPROFILE # # Import Active Directory Module # Import-Module ActiveDirectory
  • 4. Windows PowerShell – Connect to Active Directory 3 | P a g e # # Set PS Provider - Active Directory # $ADConnection=New-PSDrive -Name ADDrive -PSProvider ActiveDirectory -Root "DC=ftech,DC=com" - Server f1ind.ftech.com:389 -Credential "ftechvcp.muthukrishna" -ErrorAction Ignore if ($ADConnection.Name -eq 'ADDrive') { if ($ADConnection.Name -eq 'ADDrive') { [System.Console]::Beep(600,500) Write-host "Connected to Active Directory" -BackgroundColor Black -ForegroundColor Green } Set-Location ADDrive: Get-ADuser administrator Set-Location c: Push-Location c: Remove-PSDrive -Name ADDrive } else { Write-host "`nUnable to Connect to Active Directory" -BackgroundColor Black -ForegroundColor Red [System.Console]::Beep(600,500) } PowerShell Execution – Connect Active Directory (AD) When script is executed; the script will ask for credentials and connect to Active Directory is established when the user’s credentials are correct. This script will only list the user after connecting to Active Directory and list user’s attributes, however this script will not check or validate if the user exists or not. PowerShell Output – Key-In Authentication Information When the script is executed user has to key-In the username and password, who has access to active directory.
  • 5. Windows PowerShell – Connect to Active Directory 4 | P a g e PowerShell Output – List AD User Attribute When script is executed; once successfully establishing the connection with Active Directory, script will query and list active directory user’s attributes are listed. PowerShell Output – List AD User Attribute In this output the active directory user’s attributes are listed and the user belongs to a different Organization Unit (OU). In this example in the script we have modified the user to be connected and queried.