Moving unpingable computers

In one of my posts I described dealing with obsolete computer records, now it’s time to get a hold of the ones which are unpingable. :)

This was actually inspired by a real request in PowerGUI forums but I thought I would duplicate the answer here as well. What Ben requested in the forums was a PowerShell one-liner to bulk-move the inaccessible computers to a specific OU.

As you might guess what we need is a pipeline from Get-QADComputer to Move-QADObject with some kind of where -not pingable in between. Luckily thanks to our fellow MVP Brandon we have the script doing the ping.

So the one-liner is really very simple:

Get-QADComputer | where { -not (Test-Port($_.Name)) } | Move-QADObject -NewParentContainer ps64.local/Recycled

Add -WhatIf if you don’t want to perform the actual move. Add -Confirm if you want to be prompted for each computer record.

You can get the Test-Port from Brandon’s post over here. Copy/paste it into your PowerShell command-line before running the oneliner.

Tags: , , , , , , ,

3 Responses to “Moving unpingable computers”


  1. 1 BSonPosh October 11, 2007 at 7:51 pm

    While I appreciate the trackback, I should warn that Test-Port isn’t really a ping. It just makes a TCP Socket connection to a given port (135 RPC by default.) If you want a ping I use the function below for that. It is an actual ICMP ping. Test-Port is great if your company blocks pings or you want to specify a timeout, also the port is configurable.

    function Ping-Server {
    Param([string]$server)
    $pingresult = Get-WmiObject win32_pingstatus -f “address=’$Server’”
    if($pingresult.statuscode -eq 0) {$true} else {$false}
    }

  2. 2 halr9000 December 1, 2007 at 6:20 pm

    You may wnat to check out my Select-Alive function. It acts like a filter, making the where-object part unnecessary. Your example turns into this:

    Get-QADComputer | select-alive | Move-QADObject -NewParentContainer ps64.local/Recycled

    http://halr9000.com/article/447

  3. 3 halr9000 December 1, 2007 at 6:26 pm

    Hmm, my script might need slight modifications in order to work with $_.name. It expects $_ to be a parseable string. Seems like Guarhoth (http://thepowershellguy.com/blogs/gaurhoth/) dealt with a similar situation by checking the object type in a switch statement and pulling out the right property names as needed. I’ll have to do that. :)


Leave a Reply




View Dmitry Sotnikov's profile on LinkedIn

Follow Dmitry Sotnikov at Twitter

My Recent Tweets

Archives

See you at:

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer Quest Software or anyone else for that matter. All trademarks acknowledged.

© 2007 Dmitry Sotnikov

Pages

 

October 2007
M T W T F S S
« Sep   Nov »
1234567
891011121314
15161718192021
22232425262728
293031