Thursday, 7 May 2015

powershell: Export and import SharePoint Group to Excel using PowerShell



Export SharePoint Group to Excel using PowerShell

Export all groups and Names
add-pssnapin microsoft.sharepoint.powershell
#get the site object
$site = Get-SPSite "http://alenaldev.tawazun.ae/"
#get the group collection details
$groups = $site.RootWeb.sitegroups
#output variable is been used for storing the group details.
$Output = @("GroupName")
#loop thru the groups object and get the individual group details.
foreach ($grp in $groups)
{
Write-Host "Group: " $grp.name;
   foreach ($user in $grp.users) {
   Write-Host "user:" $user.Name

$Output += ($grp.Name+"|"+$user.Name+"|"+$user.UserLogin+"|"+$user.Email)
}
}
$site.Dispose()
#finally export the group names to the .csv file
$Output > "C:\ ExportGroups.csv"

-----------------------------------------------------

$siteUrl="SiteURLHere"
$groupName="GroupNametoExport"
$Output = @("GroupName|Name|Login|Email|Department|Title")
$web = Get-SPWeb $siteUrl
$site = $web.Site
$rootWeb = $site.RootWeb
$UserList = $rootWeb.Lists["User Information List"]
$web.SiteGroups[$groupName].Users|%{$user = $UserList.GetItemById($_.ID)
if($user -ne $null)
{
$JobTitle = $user["JobTitle"]
$Department = $user["Department"]
}
$Output += ($groupName+"|"+$_.Name+"|"+$_.UserLogin+"|"+$_.Email+"|"+$ Department +"|"+$JobTitle)
}
$rootWeb.Dispose()
$web.Dispose()
$site.Dispose()
$Output > "D:\MembersExport.csv"

Import Users from Excel to SharePoint using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$userList=IMPORT-CSV C:\UserToUpload.csv -header("GroupName","UserName")

#Get the site name to the variable
$web = Get-SPWeb SiteURLHere

foreach ($user in $userList)
{
$groupName = $web.SiteGroups[$userList.group]
$user = $web.Site.RootWeb.EnsureUser($userList.user)
$groupName.AddUser($user)
}
Write-Host -ForegroundColor green "Users Added Successfully"
}
$Web.Dispose()

REF:

http://sharepoint-works.blogspot.in/2013/01/import-users-from-excel-to-sharepoint.html#.UO1bvnfSKBw

19 comments:

  1. Great post! I am see the programming coding and step by step execute the outputs.I am gather this coding more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Sharepoint Training in Chennai

    ReplyDelete
  2. Really nice experience you have. Thank you for sharing. It will surely be an experience to someone.
    Click here:
    angularjs training in bangalore
    Click here:
    angularjs training in pune

    ReplyDelete
  3. Thank you for an additional great post. Exactly where else could anybody get that kind of facts in this kind of a ideal way of writing? I have a presentation next week, and I’m around the appear for this kind of data.
    Click here:
    angularjs Training in online
    Click here:
    angularjs training in annanagar

    ReplyDelete
  4. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Blueprism training in annanagar

    Blueprism training in velachery

    Blueprism training in marathahalli

    ReplyDelete
  5. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete
  6. hank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me 
    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  7. I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!

    Data Science Training in Indira nagar
    Data Science Training in Electronic city
    Python Training in Kalyan nagar
    Data Science training in Indira nagar

    ReplyDelete
  8. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging...

    AngularJS Training in Bangalore | AngularJS Course Fees | AngularJS 6 - i Digital Academy
    - AngularJS Training in Bangalore - Learn AngularJS 6 from Expert Real-time Trainers at i Digital Academy with Live Projects and Placement Assistance. Book a Free Demo Today.

    ReplyDelete
  9. Great site you have got here.. It’s difficult to find high quality writing like yours these days. I truly appreciate individuals like you! Take care!!

    ReplyDelete
  10. 360 Degree Image Editing Service Are you looking at the ghost mannequin effect service? We provide the invisible man14 November 2021 at 23:32

    exim classes
    EVERYTHING ABOUT EXPORT IMPORT. We are Providing All Topic Videos; We are Providing Online Training; We are Providing Offline Training. - <a href="https://www.onlineexim.com/export-importracticaltraining.php/www.onlineexim.com/export-import-practical-training.phpl</a

    ReplyDelete