Posts

Showing posts from April, 2024

AD PowerShell script to add/remove a list of users from a group

Image
Have you ever had to do something manually and you were just like, I don't ever want to do that again it took to long.  Well that happened to me when I was setting up my domain and experimenting, I had to keep adding and removing my mock users to groups and it got really annoying.  So I simply automated it using PowerShell, know all I need to do is supply a list of the users I want to remove or add and the group name then voila.  To automate this I simply went through each line in the CSV file and got the distinguished name of the user using Get-ADUser. I then used either Add-ADGroupMember or Remove-ADGroupMember to add or remove the user, all that needed to be supplied here was the distinguished name of the group and the previously gotten distinguished name of the user.  Below is a screenshot of my code, I am happy for you to use it but I am not accountable if you edit or misuse and cause any issues.  Screenshot of the code: Results of running the code:

AD PowerShell Script to see when a list of users last changed their passwords.

Image
A lot of companies have their ADs setup so that a users password will expire normally once every 6 months.  But what happens if the company was to do a password audit?  How would you know for certain that the users whose passwords were cracked had actually changed their passwords after being told to do so? Well quite simple you could ask them! But some would probably lie and say they did it when they most likely didn't. So an easier way to do this would to use a PowerShell script that imports a CSV file of all the users, then checks their AD accounts as each AD account has an attribute called PasswordLastSet. Why ask users when you can just check their accounts, at least this way you wont be lied to at all.  Below is a screenshot of my code used to run this as well as the results that came back.  I am more than happy for anyone to use this code, but take no responsibility if you change/modify this code in anyway to complete harmful/malicious actions.  Screenshot...