Get local domain controller in current AD site

Sometimes when you run scripts that rely on AD replication for subsequent steps to be successful, you will be better off not relying on AD replication but just running all commands against a single Domain Controller.
This handy little one-liner will help you assign a local domain controller to a variable and then use it throughout your script.

The command does the following:
1. Find out the DNS Root of your local domain.
2. Use that to find out all the servers in your local site.
3. Ping all of them at once.
4. Output the name of the first server that responds.

This is the command:

(Test-Connection (([System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()).Servers | ?{$_.Domain -like "$((Get-ADDomain).DNSRoot)"}).Name | select -first 1).Address

Breakdown of the command:

 ([System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()) 

– Gets your current AD Site

 ?{$_.Domain -like "$((Get-ADDomain).DNSRoot)"} 

– Uses where-object to filter out any domains that aren’t your primary dns root domain.

 (([System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite()).Servers | ?{$_.Domain -like "$((Get-ADDomain).DNSRoot)"}).Name 

– The two commands above combined to spit out a list of servers in the domain.
Test-Connection is run against this list and then we use Select -First 1 to only use the first server that responds.

Powershell Script to report on Exchange 2010 Distribution Lists

This powershell script allows you to create a report for a bunch of distribution lists that match a certain criteria. In an example here, if you want to search your entire exchange organization for all DLs (static and dynamic) that contain the word “sales”, the script would return the following information.

  1. The name of the DL.
  2. Type of DL (Static or Dynamic)
  3. Number of members.
  4. Display Name of members.
  5. Title of members.

Here’s the script: Continue reading

Powershell app to send media links to XBMC

XBMC is probably the most versatile HTPC platform out there. I have a Raspberry Pi at home running Raspbmc and I love it. I have it hooked up to my TV via HDMI and I use my TV remote to navigate around XBMC (Raspbmc has CEC support). I use the Yatse Remote app to control it and send links to it from time to time.

When using my laptop, I frequently found a need to play a link that I just found on my computer on my TV and I then found myself emailing the link to my phone and then sending it across to the Pi. It was not the best solution.

I wrote this PowerShell script to fix that problem. Continue reading

Simultaneously reboot all vApps in a vSphere datacenter

If you manage a large number of vApps in a vSphere datacenter and have to reboot them on a scheduled basis, you might not want to do it manually. This script helps you schedule the task easily.
BIG WARNING: This script is designed to run with no interaction so that it runs in the middle of the night without you having to acknowledge anything. However, the downside to doing things this way is that you can reboot all your vApps if you decide to test this on your production systems in the middle of the day.

Here’s the script: Continue reading