PowerShell Ezine, Logon Scripts

Ezine 160 - PowerShell and QAD Cmdlets

Ezine 160 - PowerShell and QAD Cmdlets

A few readers wrote in saying that my PowerShell articles were gibberish.  All I can say in reply is that this week the ezine will seem like advanced gibberish unless you: a) Install PowerShell, b) Get these famous QAD add-ons.

Topics for PowerShell and QAD

This Week's Secret - Cheating

A fresh look at QAD (Quest Active Directory) cmdlets caused me to think - 'cheat'.  This thought was followed by two more 'eureka' moments.  Firstly, the whole of PowerShell is a cheat; secondly the thought there is nothing wrong with cheating - all script writers copy and paste other people's code examples.

On a more reflective note, QAD cmdlets cheat in the sense that we no longer have to craft mechanisms which connect to active directory and then enumerate the objects.  There again, do I mind QAD cutting down my work load?  The answer is a resounding, 'No', because QADs means I can concentrate on the more interesting aspects of scripting Active Directory tasks.

ˆ

Three Pre-requisites

My speciality is getting people started.  Thus I emphasise again, you need three pre-requisites for these QAD cmdlets to work, and for my examples to produce results.

  1. Download and install PowerShell. 
    Go to Microsoft's site and choose the flavour to suit your operating system.
  2. Download, then install the QAD Snap-ins from this site:
    http://www.quest.com/activeroles-server/arms.aspx
  3. Access to Active Directory. 

QAD Snap-ins

The reason for downloading these free QAD snap-ins, with their cmdlets, is while PowerShell itself has lots of built-in cmdlets, not many specialise in Active Directory.  QAD filled this void by crafting Active Directory cmdlets and 'packaged' them into a Snap-in.  Our first job is to install that QAD snap-in.

Unless you have a passing familiarity with PowerShell, installing the snap-in (some call them snapins) is tricky.  Assuming that you have downloaded the package from QAD, here below is the PowerShell command.  What I don't know - but you do, is where on your machine you downloaded the QAD file. My point you need to edit c:\ in the command below.

# Instruction to add a QAD Snap-in
set-Location c:\
add-PSSnapin  quest.activeroles.admanagement

This Week's Mission - Get started with QAD commands

QAD techniques are identical to those of standard PowerShell cmdlets.   A good way to start is by applying classic PowerShell research tools to the QAD cmdlets, for example get-command.  It's also reassuring that QAD have included help about the parameters, moreover this help is in the same format as that for native PowerShell cmdlets.

Example 1a  get-QAD

Here is a simple technique that you can use when ever you start a new project.  Our objective is to list the QAD commands.  Get-Command is the key PowerShell cmdlet for our investigation.  I tried appending plain QAD* however, but this did not work, I needed to help PowerShell by adding a verb, for example get-QAD*

Pre-requisite  You need Active Directory.  To reduce authentication / firewall / impersonating errors, I ran all these commands on a domain controller.

 get-Command get-QAD*

Note 1:   From the results of example 1, observe the structure of the names QADxyz; where xyz could be an Active Directory User, Computer, or Group.

Note 2:  Are these QAD objects singular, or plural?  A valuable piece of knowledge is that PowerShell consistently uses only singular nouns, furthermore, Quest honours this convention and each QAD is a singular word.

Example 1b Set

'Set' is a more exciting and potentially more dangerous verb than 'get', this command would actually change the properties of active directory objects, so be careful.

 get-Command set-QAD*

Note 1:  As I hinted earlier, for safety reasons we are merely listing the available 'set' QAD cmdlets rather than putting them to work.

Note 2: Remember the PowerShell rule of verb-Noun.

Example 2a Research QADUser

Continuing this research theme, let us discover more about the QAD command.  Here is a classic opportunity for another great PowerShell command get-help with a switch called -full.

 get-Help get-QADUser -full

Example 2b QADUser in action

Our objective is to list merely those Active Directory users beginning with the letter 'a'.

 get-QADUser a*

Challenge 1: Substitute QADGroup for QADUser

Challenge 2: I liked the flexibility of QADObject, for example try:
get-QADObject -type 'organizationalUnit'

Conclusion

QADxyz cmdlets will open up a whole new world of scripting Active Directory with PowerShell.  I see my role to get you started, now it is up to you to plan, then create scripts to manage your Users, Groups and Computers.  Should you get stuck, make your first troubleshooting action: get-help verb-Noun -full.  If the script still does not work, then post question in a PowerShell forum such as: Microsoft.Public.Windows.PowerShell.


If you are looking for handy network utilities, try some of the free downloads at Tools4Ever


Summary of PowerShell and QAD Cmdlets

PowerShell's native methods of scripting Active Directory objects are tortuous.  Perhaps I have a short memory, but listing users with native PowerShell seems even more difficult than VBScript.  Fortunately, we can take advantage of the extra cmdlets that QAD kindly provide at no charge.  The only tricky part is obtaining and loading the QAD snap-in.  Once you have completed that step, commands such as get-QADUser seem part and parcel of PowerShell.

See more PowerShell QAD Scripts

PowerShell Home   • Quest QAD   • QADUser   • QAD Password   • QADGroup   • QADComputer

 • Export-CSV   • Import CSV

Please write in if you see errors of any kind.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2010 Computer Performance LTD All rights reserved

Please report a broken link, or an error.