Pass current target as variable to Powershell script
We are using PDQ Deploy to push out an application to devices and everything is working fine, but we have one step that we are having to do manually, which is add the devices to a member of an AD group.
Curious if it would be possible to add a step calling a Powershell script and pass the current target to the script as a variable? We have written a Powershell script that prompts for PC name and adds that PC to our specified group in AD (Created this script to save time from having to open AD users and computers GUI each time).
Thanks in advance! Just looking for a way to complete the automation of this application if possible.
Comments
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.
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.
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.
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.
Thank you for your help.
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.