Impractical One-liner Challenge

Published September 19, 2014 by FoxDeploy


My thanks to Mike F. Robbins and others on reddit who pointed out that the command should be ‘Select -ExpandProperty DistinguishedName’, and not organizationalUnit.

The Challenge

A colleague and I got into a competition earlier today. How could we display an Out-Gridview of all of a companies OU’s, and then move a computer to the selected one in a single line of code.

We condensed our code down to the following two lines:

$destinationOU =  Get-ADObject -Filter 'ObjectClass -eq "organizationalUnit"' | Select -ExpandProperty DistinguishedName -Unique | Out-Gridview -passthru

Get-Content .\\Computers.txt | Get-QADObject | Move-QADObject -NewParentContainer $destinationOU -whatif 

The goal? Make it into a one-liner.


  • Maintain the steps if possible.  Minimally acceptable solution:
    • Get user input for which OU
    • Get a list of computers and move them to the OU
  • NO CHEATING WITH Semicolons or backticks Doing the below doesn’t count

      $ou = Out-Gridview;gc Computers.txt | Move-Computer $ou
  • Anything else goes!

Please comment here with your answers. I’ll post my own within a few days.  Also, if you have any ideas for a future impractical One-Liner Challenge, let me know here, Twitter, or Reddit!

Microsoft MVP

Five time Microsoft MVP, and now I work for the mothership

Need Help?

Get help much faster on our new dedicated Subreddit!

depicts a crowd of people in a night club with colored lights and says 'join the foxdeploy subrreddit today'

Blog Series
series_sml_PowerShellGUI series_sml_IntroToRaspberryPi Programming series_sml_IntroToWindows Remote Management Series The Logo for System Center Configuration Manager is displayed here Depicts a road sign saying 'Learning PowerShell Autocomplete'

Blog Stats