Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Need Help with Variable Syntax

$
0
0

I am attempting to automate the creation of users and adding those users into security groups when my employer brings on a new building into our AD.

I have the user placed into a variable, and need to add that user to some security groups. However, I’m having a bit of trouble with syntax.

Using Add-ADPrincipalGroupMember like so:

Add-AdPrincipalGroupMembership -Identity $user -MemberOf “$site_groupname”

In this scenario, for the MemberOf parameter only $site is the dynamic parameter name representing the name of the site and “_groupname” is the static portion of the name of the security group. However, powershell cosiders the entire string “$site_groupname” to be the name of the variable.

Is there a way to correct my syntax so I can leave this on one combined line?

I could do it with an extra line of: $group = “$site” + “_groupName” ..but I’d rather do it on one line if possible. Perhaps this is not possible due to my use of variables within the script.

submitted by /u/Derbel__McDillet
[link] [comments]

The post Need Help with Variable Syntax appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images