Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell: Add Domain account to multiple servers

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
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 show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

809 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