Tag Archives: Windows Scripts

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

Populate Outlook Suggested Contacts from Sent Items

The smart guys over at degree.no wrote this amazing script that helps populate your Outlook Suggested Contacts folder by parsing emails you sent. This works very well, however, there was a minor issue where it does not correctly handle a case where the Display Name is blank. In such a case, the script imports the email address as the Display Name. This is not an issue with the script but an Outlook design that substitutes the display name with the email address.

I re-worked the script to handle this case better so that the final product looks cleaner i.e, your suggested contacts appear just as they would if you were to populate them over time.

Here’s the script: Continue reading