Pass current target as variable to Powershell script

Comments

5 comments

  • Stephen Valdinger

    Gosh do I love solving problems with Powershell. Alright. Let's get some questions out of the way first:

    Do you have RSAT installed on the PDQ Deploy server?

    Are you deploying the application with a user account that also has been given rights to add members to groups in AD?

    Let's start there.

    0
    Comment actions Permalink
  • dp

    Thanks for the quick response.

    Currently RSAT is not installed on PDQ Deploy server, but I can install them on there if necessary.

    We have been deploying with Local PC user account, which has local admin rights but would not have rights to edit AD.  

    0
    Comment actions Permalink
  • Stephen Valdinger

    The way I see this working the *easiest* is this:

     

    Deploy with a user that has active directory rights. 

    Run this, changing the Computername variable to a machine that has RSAT enabled on it. That can be the DC directly, or the PDQ Deploy server itself if you decide to install it there.

    Invoke-Command -Computername <computer> -ScriptBlock { Add-ADGroupMember -Identity "<Your Group>" -Members $env:COMPUTERNAME}

    When run as a step from your package, it will remotely connect to a DC via powershell, execute that command, and then go on its merry way.

    1
    Comment actions Permalink
  • dp

    Stephen,

    I was able to use your script with a few changes to get this working.  Below is what worked for me.  Our devices have Powershell v2, which may be why I had to pass PC name as an argument.  I also had to append a $ to the end of the pc name.

    $name = $env:COMPUTERNAME
    Invoke-Command -Computername ServerName -ScriptBlock { Add-ADGroupMember -Identity "GroupName" -Members $($args[0] + "$")} -ArgumentList $name

    Thank you for your help.

    0
    Comment actions Permalink
  • Stephen Valdinger

    That'll do it! Yes. Now that you mention it there is a $ at the end of the attribute in active directory. Good catch! 

    Glad it is working for you.

    0
    Comment actions Permalink

Please sign in to leave a comment.