I'm still new to PowerShell and was hoping if someone could assist.
Basically we get a few IT requests coming in asking us to add a single user to bulk server local admin AD groups. We usually copy the the specified info of these servers names in the request details field of the ticket. Example like the below:
server1 server2 server3 server4
AD example group looks like this: LocalAdmin.servername.Rights
Objective: We want to pass each of the above server name value into where servername is.
What I've done and works:
$Group = @("server1","server2")
ForEach ($Group in $Group) {
Add-ADPrincipalGroupMembership $User -MemberOf LocalAdmin.$Group.Rights
}
Problem: Where you see "server1","server2" I had to re-format that in Notepad to add quotation marks and paste it in, which is a pain, so to refine it I tried the below.
What doesn't work: I successfully got the string of "server1","server2" passed to the variable of $Servers
$Group = @($Servers)
ForEach ($Group in $Group) {
Add-ADPrincipalGroupMembership $User -MemberOf LocalAdmin.$Group.Rights
}
But I get an error of this:
Add-ADPrincipalGroupMembership : Cannot find an object with identity: 'LocalAdmin."server1","server2".Rights'
I'm expecting the user gets added to each AD group: LocalAdmin.server1.Rights, LocalAdmin.server2.Rights
But the error picks it up as LocalAdmin."server1","server2".Rights instead.
Any help would be appreciated. Thank you.