I would like to know if is it possible to create a script(power shell or vbs) that automatically insert users of a domain server folder under active directory (windows 2003).

I want to launch it on a local PC (windows) which is in the domain so as to set up users as administrators inserted automatically.

Is it possible? every day I post more than twenty users to the local machine and it is quite tiring.

  • Are you asking if you add users to the domain through a Powershell script? Yes, you can indeed do this, what have you tried. We are not a script writing service, we will be happy to help, once you have tried. – Ramhound Mar 10 '16 at 12:17
  • We are not a script writing service. We expect users to tell us what they have tried so far (including any scripts they are using) and where they're stuck so that we can help with specific problems. Questions that only ask for scripts are too broad and are likely to be put on hold or closed. Please read How do I ask a good question?. – DavidPostill Mar 10 '16 at 12:18
  • I apologize to you, I would like to automatically fill in a computer a listo of users who already exist within the Active Directory. I tried the following commands in cmd NET GROUP groupname username [...] / ADD [/ DOMAIN] NET LOCALGROUP groupname username [...] / ADD [/ DOMAIN] but the result is the opposite, from local PC I create a new group on active directory. I would like to insert Domain users within the local PC (as is done manually by the command control userpasswords2 to prompt) – Alessandro Salzano Mar 10 '16 at 13:19

There are much easier ways and better ways to do this...

Local Security Group Policy - Create a new group policy, link it to the computers you want to configure, edit the group policy and go to Computer Configuration > Policies > Windows Settings > Restricted Groups > Create a new group and call it "Administrators". Add your users to it. Now reboot your computers and they will all add the users to their Administrators Group:enter image description here

Computer Preference Group Policy - Same again, create a group policy linked to your computers and go to Computer Configuration > Preferences > Control Panel Settings > Local Users and Groups > use the "Add" function to Add users to Administrators: enter image description here

PowerShell Script

$group = [ADSI]"WinNT://$env:COMPUTERNAME/Administrators,group"
$domainName = "myDomain"

Get-ADUser -Filter * -properties * -SearchBase “OU=DefaultUsers,DC=myDomain,DC=local” | ForEach {
    $user = $_.sAMAccountName
    Write-Host (($_.sAMAccountName) + " Added")

This will error for each user who is already in the group - but I've been nice enough to give you a starter from TechNet... I'm not adapting it though - we're not a scripting service.

Domain Users as Local Admins If it is all users becoming admins on all machines, just add the "Domain Users" group to local admins manually on each machine (or through a method above) - that way, all future users will automatically become admins - given that all users are auto-added to "Domain Users" when created.

The bigger problem The bigger problem you have is that not only is this bad practise (users shouldn't be admins unless they need to be) - but it's unmaintainable.. if you have to redo all this work everytime someone new joins.

You can package something like the powershell script as a startup script on groups of machines through group policy to make this easier for you.

You can also make an Active Directory "Group" for each OU (folder) of users and just add that group to your local admins... this way, when you add someone to that group - they will become local admins from the next time they logon.

On a side note - you really need to re-evaluate security and the way things are done at your company if you're handing out admin rights to everyone.. but it's not my place to say why - maybe there's a legitmate reason, but these are few and far between.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.