1

I know the command to add the computer to an AD group, but don't know how to create a script for it using powershell?

Here's the command:

add-ADGroupMember "BRS-Groupname" -members "BAT-100971$"

I would like to get the code and extension to name it to for adding a computer account to the AD group. It would be great to have the script ask for the computername I want to be added! Thanks in advance.

Guvante
  • 18,775
  • 1
  • 33
  • 64
R0tten
  • 57
  • 1
  • 7

1 Answers1

0

So you want user input, and than you'd like to take that input and use it within your command?

Something like this?

$myVar1 = Read-Host "I have a question?"
$myVar2 = Read-Host "I have a second question?"

add-ADGroupMember "$var1" -members "$myVar2"
BRBT
  • 1,467
  • 8
  • 28
  • 48
  • I'd love to give you an upvote, but I don't have enough rep to do that. I saved the text to a file name .ps1 and when I run it, I get this: PS C:\Users\profile\Desktop> C:\Users\profile\Desktop\Add_to_BRS-Unblock-Cryptolocker.ps1 File C:\Users\profile\Desktop\Add_to_BRS-Unblock-Cryptolocker.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" fo r more details. At line:0 char:0 – R0tten Mar 17 '14 at 18:18
  • I see you've never ran a powershell script before. This here should help you out. You will need to `set-executionPolicy` to `Unrestricted`. Than try again, here is a link for further explaination http://technet.microsoft.com/en-us/library/ee176949.aspx – BRBT Mar 17 '14 at 18:30
  • @R0tten Also, instead of trying to write code in notepad, or a blank text file. Try using the PowerShell ISE, or there are plenty of free IDE's out there, personally I use PowerGUI. – BRBT Mar 17 '14 at 18:32
  • Yes, it's true, I'm a powershell n00b - sorry! I followed the steps and got it working up to the point of running the command with an error about cmdlet issue, I googled and made the changes to my shell script that I found here: http://social.technet.microsoft.com/Forums/en-US/21e371a9-0995-4ed8-9a24-a6914c233c1d/adding-an-ad-account-to-an-ad-group?forum=winserverpowershell The command that was missing is: Import-module -Name ActiveDirectory It works fine now. I wish I could upvote you. Thanks for your help. – R0tten Mar 17 '14 at 20:58
  • @R0tten hah, no worries. I am glad I could help! You could accept my answer as the correct answer(hollow check mark) so if others need help with the same problem, perhaps this solution could help them as well. Don't worry about the up vote, keep practicing your PS scripting and I am sure you will have more questions. I am learning also. Feel free to up vote when you get a chance! – BRBT Mar 17 '14 at 22:58