0

I am attempting to add a group of users to a failover cluster in windows 2012r2 I need to add the nodes as administrator to each other. I have put them into their own OU. However I was hoping to script this per powershell and a csv import. Ideas?

My google fu has not gotten me anywhere.

Example.

Import-Csv "C:\Users\me\Desktop\users.csv" | Where-Object {$_.Name} |`
 ForEach-Object {`
New-ADUser `
-Name $_."Name" `
-GivenName $_."GivenName" `
-Surname $_."Surname" `
-Description $_."Department" `
-SamAccountName $_."Logon_Username" `
-UserPrincipalName $_."UPN" `
-DisplayName $_."Display_Name" `
-AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssw0rd1!" -Force) `
-Path "OU=Users,OU=Head Office,OU=International,DC=company,DC=com" `
-ChangePasswordAtLogon $true `
-Enabled $true | Enable-ADAccount | `
Add-ADGroupMember "QA_Users" $_."Logon_Username";
}

This is what I use currently.

WHereIwantToChange

8
  • Got farther with this. still not able to get it. blogs.technet.microsoft.com/heyscriptingguy/2012/03/12/…
    – mikedopp
    Aug 19, 2016 at 19:53
  • Im still not sure with your question, on what you're trying to achieve. Can you post your csv header lines, so that i can try out the same & update you. Aug 21, 2016 at 16:38
  • If you're goal is to add/remove members, you do not need to modify ACL's in AD to do that. Do you realzie the code you're running it CREATING new users? If you're trying to modify members of the LOCAL administrators group on a cluster node Add-ADGroupMember cannot help there, it only does domain groups.
    – Clayton
    Aug 22, 2016 at 15:54
  • For posterity's sake, please copy out the code portion of your question, and use markdown for the code (indent each line by 4) and paste it back in?
    – Jeter-work
    Aug 24, 2016 at 15:53
  • Two things...you're using pipeline to create a very complicated oneliner. Consider using actual variables and building this as a script. Also, I see several instances of $.variable. I think you mean $_.variable.
    – Jeter-work
    Aug 24, 2016 at 15:57

1 Answer 1

1

There is no error handling in this. It is provided as a starting point. Craft your CSV to simplify the work by making the csv headings exactly match the AD user object property names. Then the object imported is basically a user object.

$AccountList = Import-Csv "C:\Users\me\Desktop\users.csv"
$UserOU = "OU=Users,OU=Head Office,OU=International,DC=company,DC=com"
$AccountPassword = (ConvertTo-SecureString -AsPlainText "P@ssw0rd1!" -Force)

Foreach ($Account in $AccountList) {
    New-ADUser $Account -ChangePasswordAtLogon $True -AccountPassword $AccountPassword -Enabled $True -Path
    (Get-ADUser $Account.UserPrincipalName).UserPrincipalName + "Created"
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .