Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

If you are looking to automate repetitive tasks in Active Directory management using the PowerShell module, then this book is for you. Any experience in PowerShell would be an added advantage.
Table of Contents (11 chapters)
10
Index

Finding all the disabled user accounts


Finding disabled user accounts in Active Directory is very simple. Each user object returned by the Get-ADuser cmdlet will have an Enabled property, which holds the value False when the user account is in the disabled state. Examining this value for all the user accounts in the domain will tell us how many accounts are currently in the disabled state.

The following script will query the current domain for disabled users and the exports to the CSV filename disabled-users.csv in the C:\temp folder. Make sure that the c:\temp folder exists, or you change the $OutputFilePath variable's value in the code to a folder path where you want the output to be placed:

Function Find-DisabledUsers {
[CmdletBinding()]
param(
)
$OutputFilePath = "c:\temp\Disabled-Users.csv"
Add-Content -Path $OutputFilePath -Value "UserName, DisplayName,  DistinguishedName"
$DisabledUsers = Get-ADUser -Filter { Enabled -eq $false } - Properties DisplayName
foreach($User in $disabledUsers...