5 More PowerShell Commands to Better Manage Active Directory

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.

Philip Robinson
| Read Time 3 min read| Updated On - June 16, 2020

Last Updated on June 16, 2020 by Satyendra

Recently we published a blog about five key PowerShell commands that you need to help you better manage Active Directory. As this blog was so well received, we decided to do a follow up. If you want to read the original blog, then click here.

Before We Begin

Before you get started, you’re going to have to import Module Active Directory. Without importing the corresponding module into the PowerShell session, you will not be able to run any of the cmdlets in the below list.

1. How to Find Locally Stored Password from a Computer Object with PowerShell

See below cmdlet:

Get-AdmPwdPassword -ComputerName "computer.domain.net"

For this those that want a simpler way to search for passwords stored in the computer object in AD, you will need to have implemented the Local Administrator Password Solution (LAPS) from Microsoft. It’s free and it’s an excellent way of displaying the details in a single report as opposed to having to go through each object to get the password.

2. How to Join a Computer to a Domain with PowerShell

See below cmdlet:

Add-Computer -DomainName "domain.com" -Credential Domain\Username -Restart –Force

This is a task that the average sys admin will perform hundreds, if not thousands of times during the course of their career. Joining a computer to a domain from the machine itself only takes a short amount of time but PowerShell will help you automate it altogether.

3. How to Enable/Disable Users, Computers and Service Accounts with PowerShell

See below cmdlet:

Enable-ADAccount -Identity "ComputerName"

Disable-ADAccount -Identity "Username"

This cmdlet is pretty self-explanatory in all honesty. You can use this command to allow or prevent any user or computer account from being able to authenticate with the network.

4. How to Unlock User Accounts with PowerShell

See below cmdlet:

Unlock-ADAccount -Identity "Username"

We all know the story here. The vast majority of helpdesk calls are related to users being locked out of their accounts. This leads to an inordinate amount of time required to reset the passwords of users who have forgotten them. The above cmdlet specifically applies to those accounts that have exceeded the allowed number of password entries and have been therefore locked out.

5. How to Find Inactive Users with PowerShell

See below cmdlet:

Search-ADAccount –AccountInActive –TimeSpan 90:00:00:00 –ResultPageSize 2000 –ResultSetSize $null | ?{$_.Enabled –eq $True} | Select-Object Name, SamAccountName, DistinguishedName | Export-CSV “C:\Temp\InActiveUsers.CSV” –NoTypeInformation

A large number of inactive users can seriously increase the potential attack surface of your organization. Attackers often use these accounts to leverage the permissions and move laterally across the network. The above cmdlet allows you to identify these inactive users. This cmdlet has a time frame to determine which users have been inactive for the last 90 days and exports the list into a CSV file.

These five more PowerShell commands should help you improve the basic management of your Active Directory even further. If you want more visibility into changes taking place in your AD, come and take a look at our Active Directory Auditing Solution.

Philip Robinson
Philip Robinson

Phil joined Lepide in 2016 after spending most of his career in B2B marketing roles for global organizations. Over the years, Phil has strived to create a brand that is consistent, fun and in keeping with what it’s like to do business with Lepide. Phil leads a large team of marketing professionals that share a common goal; to make Lepide a dominant force in the industry.

Get Your Free Copy of the Ultimate Guide to Active Directory Auditing
Related Articles
The Complete Guide to Effective Data Access Governance

This whitepaper provides a comprehensive guide to implementing effective data access governance.

Download Whitepaper
Data Access Governance Solution.

Better govern access to sensitive unstructured data, enforce zero-trust, and demonstrate compliance with the Lepide Data Security Platform.

Learn more