Quantcast
Viewing all articles
Browse latest Browse all 21070

Adding Users to groups using powershell

Hi,

I have written script to add users to groups through power shell script.

I am picking group names,user names from csv file as below

//inputbatch.bat file

Powershell.exe -Command Set-ExecutionPolicy "Bypass"
Powershell.exe -Command "& {E:\Addusers\addusers.ps1}"
Pause 

//addusers.ps1

$usercsv = import-csv E:\Addusers\UserPermissions.csv
                              
#Get the site name to the variable    
$web = Get-SPWeb "http://siteurl"


foreach($users in $usercsv)
{
#Get the group name to the variable
$groupName = $web.SiteGroups[$users.GroupName]
#Assign user to variable
$user = $web.EnsureUser($users.UserName)
#Add user to group 
$groupName.AddUser($user)
Write-Host -ForegroundColor green "User Added Successfully";

}

I am getting the expected output but the problem is,in the script file csv file path needs to be updated as below

$usercsv = import-csv E:\Addusers\UserPermissions.csv

Now,deployment team is allowed to update .bat file alone.

So is there any chance to update the csv file path in .bat file and manage the stuff?

Please share your ideas/thoughts on the same.

Regards,

Naga Sudheer M


Thanks & Regards, Sudheer


Viewing all articles
Browse latest Browse all 21070

Trending Articles