Clean-ADComputers.ps1

A friend of mine asked me today for a short script to clean his AD for Computer accounts that have not logged on for a certain amount of time. No problem. For this I first built a really short script of only five lines that checked the LastLogon on the computer accounts which I retrieved by Get-ADComputers. However at that moment I remembered that the LastLogon does not replicate between DCs, why I had to go out to each DC, get the accounts and then consolidate to make sure I only disabled the “really inactive” accounts (and for those who in this moment are thinking of lastLogonTimestamp that attribute does by default not have the right replication resolution to be used for this purpose.) So below is my result script, download and use.

Export-PasteBin.ps1

Do you know Pastebin? Well if you don’t, it is a web based clip-board where you can store scripts and other stuff temporarily and also share it. It’s not a place for secrets but you can create your own sub-domain and your own Pastebin site. Goto http://pastebin.com to learn more about their service.

This is a short script that can take code via command line, code via file or object via pipe and publish that directly to Pastebin. No more copy-paste. Enjoy!

Show-MessageBox.ps1

Today while teaching a PowerShell class I got the question about how to produce simple forms and dialogs. I just did some .net loading and away I was. During the following lab I wrote a small wapper to mimic the behaviour of VBScripts MsgBox. It’s a very simple scripts, accepts four string inputs: title, message, buttons (like OK, YesNo etc) and icon (None, Hand, Warning etc). The return from the script is also converted to a simple string to make it easy to implement and compare. Use it if you like it.

Get-ADUserReplicationData.ps1

Today I needed to find the changedate for some of the attributes of a specified used. The obvious answer here was PowerShell (duh!) and here is the small script I came up with as a quick and dirty (somewhat modified to be more generic than my original implementation). The scripts pulls up the default context (domain) and a random domain controller and polls that machine for metadata. The results are returned for further processing. Download the script and rename it to .ps1 and try it out!