[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Powershell: Add Domain account to multiple servers

Posted on 2014-02-26
2
Medium Priority
?
667 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Loops Section Overview

872 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