Solved

Powershell: Add Domain account to multiple servers

Posted on 2014-02-26
2
660 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

832 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