Posts

Showing posts with the label add remove read sharepoint groups

SharePoint: Powershell scripts for reading, deleting and adding Groups from a Site Collection

Here are couple of Powershell scripts to play around with the SharePoint groups and users. Reading All the Users and Groups in a Site Collection $site = Get-SPSite "SiteCollection URL" $groups = $site.RootWeb.sitegroups foreach ($grp in $groups) {"Group: " + $grp.name; foreach ($user in $grp.users) {" " + $user.loginname + " "} } $site.Dispose() Adding Groups, Permission and Users to the respective groups to a Site Collection: Function AddSnapIn() { #handles exceptions caused by trying to add a snapin Trap [Exception] { continue; } #Check that the required snapins are available , use a comma delimited list. #example # ("Microsoft.SharePoint.PowerShell", "Microsoft.Office.Excel") $RequiredSnapIns = ("Microsoft.SharePoint.PowerShell"); ForEach ($SnapIn in $RequiredSnapIns) { if ( (Get-PSSnapin -Name $SnapIn -ErrorAction SilentlyContinue) -eq $null ) { Add-PsSnapin $SnapIn } else ...