Solved

Powershell: Add Domain account to multiple servers

Posted on 2014-02-26
2
659 Views
Last Modified: 2014-02-27
Hi EE

Can you someone help me modify this script so I can add a domain account instead of a group ?


$ErrorActionPreference = "Stop"
GC Servers.txt | %{
$Serv = $_
$domain="MyDomain"
$group = "GroupName"
      Try {
      ([adsi]"WinNT://$Serv/Administrators,group").Add("WinNT://$domain/$group,group")
      "" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Success"}}
      }
      Catch{
      "" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Failed"}}
      }
}



I canged the variable to $account and the line below and it failed .

This:
      ([adsi]"WinNT://$Serv/Administrators,group").Add("WinNT://$domain/$group,group")

to:
      ([adsi]"WinNT://$Serv/Administrators,group").Add("WinNT://$domain/$account,account")
0
Comment
Question by:MilesLogan
2 Comments
 
LVL 51

Accepted Solution

by:
Netman66 earned 500 total points
ID: 39890977
Rather than $account, it should be $user.

So, try this:

$ErrorActionPreference = "Stop"
GC Servers.txt | %{
$Serv = $_
$domain="MyDomain"
$user = "UserName"
      Try {
      ([adsi]"WinNT://$Serv/Administrators,group").Add("WinNT://$domain/$user,user")
      "" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Success"}}
      }
      Catch{
      "" | Select @{N="Server";e={$Serv}},@{N="Status";e={"Failed"}}
      }
}

Change the variable for $user to whatever the user's name is (sAMAccount name).
0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39892528
That was it ! thank you so much
0

Featured Post

Do email signature updates give you a headache?

Do you feel like all of your time is spent managing email signatures? Too busy to visit every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Join & Write a Comment

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
This article will help you understand what HashTables are and how to use them in PowerShell.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now