Windows Vista Forums

trapping error messages froom get-qaduser
  1. #1



    Newbie
    Join Date : Jul 2007
    Posts : 2
    XP
    Local Time: 11:59 AM

    trapping error messages froom get-qaduser

    i'm currently pulling a list of usernames from a mysql database and storing it within a variable, and using that variable to query AD with get-qaduser. my ultimate goal is if the user exists in the db but not in AD to put that user's info into a file. the problem that i'm having is it appears that get-qaduser is not generating any errors when when it doesn't find a particular user, it just moves on to the next value. if i supply the users directly via the command line one at a time, it will generate an error for a non-existant user. any ideas? following is a snippet. Thanks in advance.


    while ($dr.read()){
    $ms = Get-Content "c:\sg.txt"
    $mailbox = select-random.ps1 $ms
    $samname = $dr.getvalue(1)
    $fname = $dr.getvalue(2)
    $mi = $dr.getvalue(3)
    $lname = $dr.getvalue(4)
    $forward = $dr.getvalue(7) + $dr.getvalue(8)
    $names = $Fname + " $mi" + " $lname"

    # Check AD for username. set variable for output and error and try to capture that in a file

    get-qaduser -samaccountname $samname -ov out -ev err -ea stop

    $out >> "C:\pshell\create_users\$now.txt"
    $err >> "C:\pshell\create_users\err.txt"

    "User ID: " + $samname
    "Name: " + "$Fname " + "$mi " + "$lname"
    "Forwarding Mailbox: " + $forward+"-in"
    "Mail Store: " + $mailbox
    ""
    ""


      My System SpecsSystem Spec

  2. #2


    Gaurhoth Guest

    Re: trapping error messages froom get-qaduser

    What about testing the result of get-qaduser instead of relying on an exception? Example:


    PS> $user = get-qaduser -samaccountname $samname
    PS> if (!$user) { write-Host "Account Not Found" }
    Account Not Found

    gaurhoth


    "blittle" <blittle.2tbgo2@no-mx.forums.net> wrote in message news:blittle.2tbgo2@no-mx.forums.net...
    >
    > i'm currently pulling a list of usernames from a mysql database and
    > storing it within a variable, and using that variable to query AD with
    > get-qaduser. my ultimate goal is if the user exists in the db but not
    > in AD to put that user's info into a file. the problem that i'm having
    > is it appears that get-qaduser is not generating any errors when when it
    > doesn't find a particular user, it just moves on to the next value. if i
    > supply the users directly via the command line one at a time, it will
    > generate an error for a non-existant user. any ideas? following is a
    > snippet. Thanks in advance.
    >
    >
    > while ($dr.read()){
    > $ms = Get-Content "c:\sg.txt"
    > $mailbox = select-random.ps1 $ms
    > $samname = $dr.getvalue(1)
    > $fname = $dr.getvalue(2)
    > $mi = $dr.getvalue(3)
    > $lname = $dr.getvalue(4)
    > $forward = $dr.getvalue(7) + $dr.getvalue(8)
    > $names = $Fname + " $mi" + " $lname"
    >
    > # Check AD for username. set variable for output and error and try to
    > capture that in a file
    >
    > get-qaduser -samaccountname $samname -ov out -ev err -ea stop
    >
    > $out >> "C:\pshell\create_users\$now.txt"
    > $err >> "C:\pshell\create_users\err.txt"
    >
    > "User ID: " + $samname
    > "Name: " + "$Fname " + "$mi " + "$lname"
    > "Forwarding Mailbox: " + $forward+"-in"
    > "Mail Store: " + $mailbox
    > ""
    > ""
    >
    >
    > --
    > blittle


      My System SpecsSystem Spec

  3. #3


    Rostislav.Pridatko@quest.com Guest

    Re: trapping error messages froom get-qaduser

    get-qaduser -samaccountname $samname
    is a search for users with a specific samAccountName, it can return
    several users and it shouldn't return an error if it has found none.

    OTOH,
    get-qaduser $identity
    is a bind attempt and it will throw if none or more than one user is
    found. $identity can be specified in many ways (read the docs or
    output of get-help get-qadUser -full for full list). For example,
    valid values for Identity are
    domainNetbiosName\accountName and user principal name so you can use
    something like this:
    get-qaduser "domainNetbiosName\" + $samname
    or
    get-qaduser $samname + "@domain.dns.name"
    You can even specify exactly the type of Identity (so the cmdlet won't
    have to analyze the value of Identity param) using the disambiguation
    prefix (advanced and probably underdocumented feature):
    get-qaduser "account=domainNetbiosName\accountName"
    get-qaduser "upn=accountName@domain.dns.name"

    BTW, if you just want to compare contents of CSV file with the
    contents of some OU you can just do this:

    $diff = Compare-Object $(import-csv sample.csv) $(Get-QADUser -ou
    domain.dns.name/myOu) -property DN

    This assumes you have a DN column in CSV, but you can use another
    property.

    And one more thing: you can post questions related to Quest cmdlets (*-
    qad*) to the following forum:
    http://www.powergui.org/forum.jspa?forumID=173
    This is the support forum for the Quest AD mgmt snapin and is
    monitored by the developers of this snapin (myself included).
    HTH


      My System SpecsSystem Spec

  4. #4



    Newbie
    Join Date : Jul 2007
    Posts : 2
    XP
    Local Time: 11:59 AM


      Thread Starter

    Re: trapping error messages froom get-qaduser

    Thanks alot for your help. i ended up setting the output variable and doing an "if $outvar is null" then send to "filename". Not very elegant, but i'm still a noob .


    foreach ($name in $samname) {
    "name is $name"
    get-qaduser -samaccountname $samname -ov outvar | Out-Null

    if ($outvar -ne $null) {
    echo "UserID: $samname" "Name: $Fname $mi $lname" "Forwarding Mailbox: $forward-in" "Mail Store: $mailbox" "" "" >> "C:\pshell\create_users\out.txt"
    }
    else {
    echo "UserID: $samname" "Name: $Fname $mi $lname" "Forwarding Mailbox: $forward-in" "Mail Store: $mailbox" "" "" >> "C:\pshell\create_users\err.txt"
    }
    }

      My System SpecsSystem Spec

trapping error messages froom get-qaduser problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
error trapping? Justin Rich PowerShell 6 14 Jan 2009
trapping a particular type of error andy-powershell.com PowerShell 4 27 Aug 2008
Another error trapping problem Rob Campbell PowerShell 2 25 Jan 2008
Help w/ error trapping Blip PowerShell 3 12 Feb 2007
trapping error and then continue IT Staff PowerShell 1 23 Jan 2007