header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Overloading with Get-QADuser
Last Post 21 Oct 2011 12:08 AM by Bobdee. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BobdeeUser is Offline
Basic Member
Basic Member
Posts:130
Avatar

--
20 Oct 2011 08:09 AM
    Hi - I'm attempting to write a function with 2 overloads that will allow me to perform a get-qaduser on a specific user and return a specific attribute.

    Now, I can use overloads normally IE - on a sql query, or just to write the overloads to console...  But, trying to use them with get-qaduser is another thing.  I am able to use one overload to query ad for the user, or for the attribute, but not both.

    Can anyone offer any help?  Below is the simple function and the error returned, and an example of one overload.

    Thanks in advance

    Rob.


    function adUserSpecific ($userName , $attrib) {

      Get-QADuser $userName -DontUseDefaultIncludedProperties -IncludedProperties $attrib | select $attrib

    }

    adUserSpecific ('user123' , 'userprincipalname' )

    Get-QADUser : Cannot validate argument on parameter 'IncludedProperties'. The argument is null or empty.
     Supply an argument that is not null or empty and then try the command again.
    At line:5 char:78
    +   Get-QADuser $userName -DontUseDefaultIncludedProperties -IncludedProperties <<<<  $attrib | select $
    attrib
        + CategoryInfo          : InvalidData: (:) [Get-QADUser], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Po 
       wershell.Cmdlets.GetUserCmdlet

    =================================  Example of overload working.
    function adUserSpecific ( $attrib) {

      Get-QADuser ca-rdixon -DontUseDefaultIncludedProperties -IncludedProperties $attrib | select $attrib

    }

    adUserSpecific ( 'userprincipalname' )


    UserPrincipalName                                                                                       
    -----------------                                                                                       
    user123@myDomain.net


    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    20 Oct 2011 11:47 AM
    Consider this:
    PS > function test ($foo,$bar) {"first: $foo";"second: $bar"}
    PS > test ("abc","123")
    first: abc 123
    second:
    PS > test ('abc','123')
    first: abc 123
    second:
    PS > test "abc","123"
    first: abc 123
    second:
    PS > test "abc" "123"
    first: abc
    second: 123

    PowerShell is not parsing the arguments like you might thing it is doing it. You need to provide 2 separate strings.
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    21 Oct 2011 12:08 AM
    Thanks Marco - as always. This worked perfectly.

    Rob.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer