Jump to content

Hello everyone,

 

I'm at work and have been given the project of writing a Powershell cmdlet that will add a user to a active directory group, to give them access to certain things (eg; websites, server files)

 

The cmdlet also has to send emails to the users and so on, but i have figured that our for myself, does anyone have any suggestions of sites to look at? Or even some help with the script itself?

 

Thanks :)

Link to comment
https://linustechtips.com/topic/429056-powershell-script-help/
Share on other sites

Link to post
Share on other sites

You will need the activedirectory module for PowerShell.

Import-Module activedirectory

If that fails you need to install the Remote Server Administration Tools (Active Directory Users and Computers, and so on.) 

 

After that it's stupid simple using Add-ADGroupMember

Import-Module ActiveDirectoryAdd-ADGroupMember MyGroup Bob.Smith,Jane.Doe,John.Doe

You can of course do something more complex like:

Import-Module ActiveDirectory$Users = Import-CSV .\Users.csvforeach ($User in $Users) {    Add-ADGroupMember -Identity MyGroup -Member $User.username}# Format the CSV as a single column with a header "username"

You can also copy members from one group to another...

Import-Module ActiveDirectory$Members = Get-ADGroupMember -identity Group1foreach ($i in $Members) {     Add-ADGroupMember -Identity Group2 -Members $i }
Link to comment
https://linustechtips.com/topic/429056-powershell-script-help/#findComment-5756527
Share on other sites

Link to post
Share on other sites

Hello everyone,

 

I'm at work and have been given the project of writing a Powershell cmdlet that will add a user to a active directory group, to give them access to certain things (eg; websites, server files)

 

The cmdlet also has to send emails to the users and so on, but i have figured that our for myself, does anyone have any suggestions of sites to look at? Or even some help with the script itself?

 

Thanks :)

Basically sounds like everything is built-in.

 

Make a function and have it accept the following paramaters firstname lastname and depending on where that email needs to go, an email address also.

Function NEWUSER ($fname, $lname, $demail) {    Import-Module ActiveDirectory #not required on PS version 3+ (or was it two plus?)    New-ADUser -Name $fname[0]$lname -GivenName $fname -Surname $lname -UserPrincipleName -$fname[0]$lname@[member=Domain16]    etc     etc}

Then you just set this to load as part of your powershell profile and then just run like any other cmdlet.

 

Omniomi has the right idea for giving access to files, etc give access to a group then assign member to the group.

 

EDIT: ignore my response I can't read your question.

Link to comment
https://linustechtips.com/topic/429056-powershell-script-help/#findComment-5760327
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×