Scripts: Active Directory

« All scripts

Powershell466 lines

Find Which Computer a Domain User Last Logged On From

Active Directory stores when a user last logged on, but not where. This script fills that gap by querying the Security event log across every domain controller, correlating Kerberos and NTLM authentication events, and resolving them to a computer name. Run it when a user reports a problem and you need to know what machine they were on, or when you’re chasing down suspicious activity and need a starting point.

Read »
Powershell345 lines

PowerShell: Bulk Add Users to Microsoft Entra Groups

This script adds lists of users to one or more Microsoft Entra ID groups in bulk, using the Microsoft Graph PowerShell SDK. It’s built for license-group provisioning scenarios where you need to drop a batch of UPNs into specific groups and get a clear record of what happened. You’d run this when onboarding a wave of users, rolling out a licensed feature, or cleaning up group membership after an org change.

Read »
Powershell130 lines

PowerShell Login Script: Drive Mapping and Greeting Popup

This script is a modern PowerShell replacement for the classic VBScript logon script. It maps network drives for all users, maps additional drives based on AD group membership, and shows a time-of-day greeting popup at login. Deploy it via GPO under User Configuration > Policies > Windows Settings > Scripts (Logon), PowerShell Scripts tab.

Read »
Text

Managing AD Groups with PowerShell

As a Windows system administrator, managing Active Directory (AD) groups is probably something you do every day. While you could use the Active Directory Users and Computers (ADUC) MMC snap-in, what happens when you need to manage groups across multiple domains or automate group management tasks? That’s where PowerShell comes in handy.

Read »
Powershell98 lines

PowerShell Script: Pull Domain Info from Any Domain-Joined PC

This script collects a snapshot of everything domain-related on the local machine: join status, logged-on users, secure channel health, time sync source, AD site, network config, and key AD domain details. Run it when you’re troubleshooting a domain issue and want all the relevant facts in one shot instead of running eight separate commands.

Read »
Powershell71 lines

Add a User to Multiple AD Groups at Once

This script takes a list of email addresses and adds those users to a defined set of AD groups, skipping anyone already a member. You’d run this when onboarding someone who needs access to several groups at once and you don’t want to click through ADUC five times.

Read »
Powershell198 lines

Copy AD Group Memberships Between Computers in Bulk

This script reads two CSV files — a list of source computers and a matching list of target computers — and copies every AD group membership from each source to its corresponding target. You’d run this when migrating machines, replacing hardware, or provisioning new endpoints that need to inherit an existing computer’s group assignments without doing it manually one by one.

Read »