Ping a List of Computers

| February 28th, 2018

Have you ever had a list of IP addresses that you need to ping, and check for DNS entry? Have you ever had to do it manually, one at a time? I did, wayyyyyy before I learned how to automate the mundane.

Now, the following script is not as pretty as it could be, but it serves me fine because I just need it to get the data, and I do the rest of the formatting in Excel.

#Create your output file with headers.
#(it will do this each time you run the script, to reset the file.)
$OUTPUT = “IP| STATUS| HOSTNAME” | Out-File .\pingList-Report.csv

#Import your list of IP addresses. They should be in a file called ipaddresses.csv, single column with a header of “ipaddress”.
$TOPING = (import-csv .\ipaddresses.csv).ipaddress

#Loop through the IP Addresses from the ipaddresses.csv file
foreach ($ip in $TOPING){

#First, resolve the hostname by performing a DNS lookup.
$HOSTNAME = (resolve-dnsname $ip -ErrorAction SilentlyContinue).namehost
#Ping the IP using the “test-connection” cmdlet, and if it responds (if the condition is true) set the status variable to “ONLINE”
if (Test-Connection $ip -Count 1 -Quiet) {
else {
#If it doesn’t respond (if the condition is anything but true) set the status variable to “OFFLINE”
#Output the results from this IP to the file, and move on to the next IP.
$OUTPUT = “$ip| $PINGSTAT| $HOSTNAME” | Out-File .\pingList-Report.csv -Append

That’s the whole script. The input file (ipaddresses.csv) should be formatted as such:


The Output file will look similar to this:


Once you have this CSV, you can import ==> From Text File in Excel, and set the delimter as the pipe “|” character.

You may be wondering why I use the pipe instead of actually using a CSV. Well, I pull a lot of data from Active Directory and Exchange using powershell, and unfortunately its still not easy to separate fields such as “DisplayName”, which is typically “Lastname, Firstname”. The comma between the two names tends to be read as two separate fields when you import into Excel. By using Out-File and delimiting using pipe or “|” it allows me to use a character that is rarely used in any field in either AD or Exchange, and ensures that there is no confusion in fields that contain a comma as part of the data.

Thanks for reading, and feel free to post comments below. I’d love to hear if this script worked for you, and/or any enhancements you may have made to it!


Restore AD Account

| February 25th, 2018

Every Active Directory Admin has done it.  Delete a user (or users), and for one reason or another you need them back.  Well, there’s a solution in the Active Directory Reycle Bin.

This feature should have been thought of a long time ago, but it’s been around long enough now that I can’t really complain too much.  Its very simple to use (once it’s enabled), and saves a ton of time that you would otherwise be using to re-create, or restore the accounts from a backup of some kind.

Now, I’m not going to get into how to enable this feature.  I reserve this blog for quick posts, with simple commands or scripts that you can start using right away.  If you do a search for how to enable it, I guarantee you’ll find a number of websites with screenshots to guide you through it.

Find Your Deleted User

In order to restore the user, you first have to find them.  To do this, you have to use the Get-AdObject command, which if you’ve used it before, you know how frustrating it can be sometimes.

Get-AdUser -Filter ‘ObjectClass -eq “User” -AND IsDeleted -eq $True -IncludeDeletedObjects -Properties IsDeleted, LastKnownParent | fl

The command above will find deleted user objects, and show you not only the name, but the LastKnownParent (last known OU).  Once you have the list, you can add more items to the filter list to narrow down your search, and then pipe the results to the restore command.

Restore Your Deleted User

Now that you’ve found your user, restoring is simple.  You can simply pipe the results to the Restore-AdObject command.

Get-AdUser -Filter ‘ObjectClass -eq “User” -AND IsDeleted -eq $True -IncludeDeletedObjects -Properties IsDeleted, LastKnownParent | Restore-AdObject

This is the simplest way to perform the restore, and will put the object back into it’s last known OU in your AD tree.  There are many other ways to narrow down the users, or specify an alternate OU, but I wanted to cover the simplest possible scenario for people looking for a quick fix to their problem.   If there is demand for more info, I’ll write a follow up post, so let me know in the comments below.

Hello world!

| November 15th, 2016

PS C:\>notepad.exe .\helloWorld.ps1

#Hello World - First Post to
$OUTPUT = "text" | Out-File .\greeting.csv
$OUTPUT = "Hello, World!" | Out-File .\greeting.csv -Append

$greeting = (import-csv .\greeting.csv).text

foreach ($item in $greeting) {

     if ($item -ne $null) {
          write-host $item

PS C:\>.\helloWorld.ps1

Hello, World!

PS C:\> _