Tag Archives: windows

Ping a set of hosts with Powershell

You may find yourself one day having to ping a set of machines on a regular basis. Rather than drop to a Command Prompt and type in ping followed by each and every host name, wait for the results and move on to the next host name I asked myself there has got to be a better way to do things.

In comes the Powershell command Test-Connection.

Test-Connection is essentially the Powershell equivalent of the Ping command but with all the scripting benefits of being a Powershell command as well as being very expandable and customisable.

For my example environment; I have a couple of test sites and couple of different roles in each site and my naming convention is based around this (hosts are named site-role). Often sites are spun up or brought down so I wanted the script to be modular rather than hard code the host names somewhere directly. Thus with this script there are three files in total:

  1. ping.ps1
    The powershell script shown below
  2. sites.txt
    A list of the site names
  3. roles.txt
    A list of role names

So without further ado, below is the PowerShell code to grab and put into your ping.ps1 file:

#Set Variables for AD Sites, Workstation Roles + Collection
$sites = Get-Content sites.txt
$roles = Get-Content roles.txt
$collection = $()
#Grab Site Name
foreach ($site in $sites)
    #Add the Role Name
    foreach ($role in $roles)
            #Combine Site + Role to create DNS name "site-role"
            $server = "$site-$role"
            $status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) }
            #Ping DNS name via PS command Test-Connection once
            if (Test-Connection $server -Count 1 -ea 0 -Quiet)
                    $status["Results"] = "Up"
                    $status["Results"] = "Down"
            #Output status of ping along with timestamp
            New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
            $collection += $serverStatus

The script is already commented out to explain things step by step but essentially, for each site in sites.txt, powershell will Test-Connection once for each role in roles.txt and output the result complete with Up/Down status, a timestamp and the hostname.

Give it a try in your environment. Maybe you can expand the script and get it to log to an Excel file?

Piping Command Line output to clipboard

Piping output of applications is nothing new to those in the profession of IT (especially the *nix administrators out there) but there was a feature added to Windows 7/Server 2008 R2 that doesn’t seem to be widespread.

Any command that you enter at the Command Line prompt or CMD as we all know it as can be piped to the Windows clipboard with a simple argument. All you need to do is at | clip to your command.

For example, let’s pipe a list of power plans using powercfg to the clipboard:

powercfg -list | clip

The output of this looks like the below:


Notice how there is…no output.

Now let’s head into notepad and paste what is on the clipboard:


Hey presto, all the output from the command that would have displayed at the CMD prompt was piped into the clipboard and now into whatever output of your choosing (in this case, Notepad).

Fellow SysAdmin’s know what to do


Cheers to fellow redditors for the find

Windows 8.1 & Server 2012 R2 release dates announced


If you have been hanging out for the latest release of Windows for either your home computer or your server farms the wait is almost over.

Microsoft have set the date, October 18th (for those in Australia & NZ, 17th for those in the States and everywhere else) for the general release. Please note, RTM availability is usually before general availability, so for those of us with the dead man walking TechNet subscriptions expect downloads to be made available earlier.

Windows 8.1 (as well as RT), despite Microsoft ditching the traditional release followed by several service packs cycle, will be released for free for those who already own Windows 8.

Windows Server 2012 R2 will be released through traditional channels and feature along side refreshed versions of System Center and Windows Intune as part of the dubbed R2 wave update.

Discover more about the Windows 8.1 release here and the 2012 R2 here

Make time to set (NTP) time

Any any Windows domain environment one of the most overlooked but ultimately crippling when things are wrong component is time. If your Domain Controllers, other servers and clients are not in sync with one and another you’re going to have a bad time.

Yes I just went there, internet memes and all…

So what are the best methods for keeping things in sync. Windows does a good job of keeping everyone in sync with your nearest Domain Controllers but if your Domain Controllers are getting their time from different sources or are muddled up possibly due to virtualization that is when you will start to get grief.

I recommend doing two things:

Set an external network time source

Go to your Primary Domain Controller and type the following at an elevated command prompt:

w32tm /config /manualpeerlist:"timeserveraddress.com" /syncfromflags:manual /reliable:yes /update

Where timeserveraddress.com is replace with your favourite reliable NTP server. If you don’t have one in mind a good place to start is http://www.pool.ntp.org and pick a server that is closest to you geographically.

Once set, let’s confirm our command has worked by typing the following at an elevated command prompt:

w32tm /query /peers

You should receive an output similar to the following:

Once you have confirmed the external time source is set the next move is to get the rest of your ducks (Domain Controllers) in a row.

Set your Primary Domain Controller as the time source for the other Domain Controllers

Do the following at an elevated command prompt on the rest of your Domain Controllers:

net time \\primarydomaincontroller /set

Where \\primarydomaincontroller is replace with the NETBIOS name of your Primary Domain Controller that was just setup with an external network time source.

That’s it, all done. Your clients will look to their nearest Domain Controller for their time and those Domain Controllers will get their time from the Primary Domain Controller which will get the time from your choice of external time source.

Note: this setup is just a recommendation. You can switch things up to increase redundancy as the current setup has two single point of failures (external time source and Primary Domain Controller). To increase redundancy simply point your additional Domain Controllers to the same external time source (or different ones if you want SUPER redundancy but I don’t recommend this as it could introduce error rather than prevent it) rather than your Primary Domain Controller

Certified Part 1

Microsoft Certified Professional LogoAs of yesterday I am now a Microsoft Certified Professional (Technology Specialist: Windows 7, Configuration for those keeping score at home).

For a long time I flirted with the idea of getting certified for all kinds of things but never put in the time to get it done. The biggest barrier is I am not much of a big reader of anything in text-book form (and is most likely why I never did as well as I should in Physics and Math Methods back in my VCE days). So while I wanted the title it just never came about.

That was a few years ago and since then I have under gone a change in mindset when it comes to all things life. I began personal training after gathering with friends and realising we all wanted more from ourselves. This began a chain of events that ultimately resulted in me being more confident in myself, more willing to take risks, more willing to put myself outside my comfort zone and most importantly hungry to be the best I can possibly be.

I cannot stress how important that pushing my body in personal training is to being a better me (or you). It isn’t purely about physical appearance or strength (that’s a great bonus). Some people may write off this kind of thing as macho or neanderthal but that is half the point. Our day-to-day lives (especially for people in IT) are simply boring for the body, yet our body was designed from the outset to move, to be physical. Without this being satisfied, our body as a whole is working to nowhere near its peak. If we want to train our brain to be more intelligent it will be quite a struggle if the body is in poor shape as they are both connected intricately. In short, just like it has always been stressed to have a balanced diet of food, so too should you have a balanced regiment of training the body and the mind.

Fast forward to the start of June and I am on Long Service Leave from my current job and rather than take a holiday I decided to help out a start-up based in Hong Kong that develops golf training and analysis devices that I (and many of my close friends) am invested in. I helped out where I could, doing things like soldering, assembly work, social media marketing and many other tasks no way in relation to my career in IT.

So how does this relate to becoming certified you ask? Well, around mid August, the work I could get involved with was starting to dry up. It is at this time that I started to review my resume with job prospects being discussed, I found that while my 7 years of experience is phenomenal at my age and is invaluable I couldn’t help but want something more on my resume…something to give it a bit of polish. My mind wandered back to certifications and I had a eureka moment that I could use all this free time to study with the possibility of earning that industry title.

Excited by the prospect I started to research what I could achieve with the limited resources I had at my disposal and my current experience. When I released there was a testing centre 10 minutes away from my current location and it was more than %50 cheaper here in Hong Kong than back in Australia the seed was planted.

In the next part I will share what resources I used to achieve my certification and more musings over the entire process.