I’ve been working on a simple PowerShell command today to import into our endpoint management solution so we can alert on disks with low diskspace. It’s been a while since I’ve dabbled with PowerShell, and it reminded me just how flexible it is and much I love it!
So I thought I would walk you through the evolution of the command I ended up with.
In this article we’ll look at using Get-ADComputer and Set-ADComputer to list computer accounts which haven’t logged in for xx days, and then automatically disable them.
In part 1 we looked at how to use Get-ADComputer to list computers by name and sort them by their last logon date with the premise that we can use the information to remove historic computer accounts from the domain.
Now we know the computer accounts we want to work with we will look at modifying the PowerShell command to automatically disable them.
I’ve written about Get-ADUser several times already to find out Active Directory user information, but in this post we’ll be using Get-ADComputer to find out the last logon date for the computers in Active Directory.
As computers are retired or fail and are replaced how often do admins remember to remove the computer accounts from Active Directory?
You can use the command we are going to create below to enumerate the last login date for all the computer accounts in your domain, so that you can safely disable and remove them after they have been inactive for a period of time. Continue reading →
In Part 1 we looked at the Get-ADUser command, and used it to create a list of all users and display their homedrive, homedirectory and scriptpath.
In this post we’ll look at refining the results a little.
We’ll look at sorting the results, only returning results for user accounts that have a login script, and export them to CSV, which is much more useful than exporting the results to a text file. Continue reading →