In my last post, I ran through how to use PowerShell for adding SharePoint groups or Active Directory users/groups with a specific permission level to all sites in a site collection. Here, I am going to use the same process for removing assignments on users and groups from all sites.
The script steps through each site and removes the account specified. I have also included an option to skip the root site, should you wish to remove the account from sub-sites only. Note: Using this script will not delete users and groups from the site collection permanently – even if all their permissions are removed from every site. They will still exist in the site collection for future permission assignment, if required.
As before, you will need to run the function first in a PowerShell console with the SharePoint cmdlets loaded (e.g., the SharePoint 2010 Management Shell) before anything can be modified. I have annotated portions of the script so that you can hopefully follow what it is doing:
function RemoveAccountFromAllSites ($siteURL, $accountName, [switch]$skipRootSite)
{
#Get Site Collection
$site = Get-SPSite $siteURL
#Check if the accountName variable contains a slash - if so, it is an AD account
#If not, it is a SharePoint Group
$rootWeb = $site.RootWeb
if ($accountName.Contains("\")) { $account = $rootWeb.EnsureUser($accountName) }
else { $account = $rootWeb.SiteGroups[$accountName] }
$rootWeb.Dispose()
#Step through each site in the site collection
$site | Get-SPWeb -limit all | ForEach-Object {
#Check if the user has chosen to skip the root site - if so, do not change permissions on it
if (($skipRootSite) -and ($site.Url -eq $_.Url)) { write-host "Root site" $_.Url "will be bypassed" }
else {
#Check if the current site is inheriting permissions from its parent
#If not, remove permissions on current site
if ($_.HasUniqueRoleAssignments) {
write-host "Removing account" $accountName "from site" $_.Url
$_.RoleAssignments.Remove($account)
}
else {
write-host "Site" $_.Url "will not be modified as it inherits permissions from a parent site."
}
}
}
#Display completion message and dispose of site object
write-host "Operation Complete."
$site.Dispose()
}
Then, use the function to remove users and group assignments in the site collection, as shown in the following examples:
- Remove the Active Directory user “PACDOMAIN\Phil” from all sites except the root site
RemoveAccountFromAllSites –siteURL “http://portal” -accountName "PACDOMAIN\Phil" -skipRootSite
- Remove the Active Directory user “PACDOMAIN\Phil” from all sites including the root site
RemoveAccountFromAllSites –siteURL “http://portal” -accountName "PACDOMAIN\Phil"
- Remove the Active Directory group “PACDOMAIN\Portal Users” from all sites including the root site
RemoveAccountFromAllSites –siteURL “http://portal” -accountName "PACDOMAIN\Portal Users"
- Remove the SharePoint group “Test Group” from all sites except the root site
RemoveAccountFromAllSites –siteURL “http://portal” -accountName "Test Group" –skipRootSite
Below is an example output you receive in the console when running the script:
Root site http://portal will be bypassed
Site http://portal/perminherited will not be modified as it inherits permissions from a parent site.
Site http://portal/perminherited/InheritedSite will not be modified as it inherits permissions from a parent site.
Removing account Test New Group from site http://portal/perminherited/UniqueSite
Removing account Test New Group from site http://portal/permuniquesite
Site http://portal/search will not be modified as it inherits permissions from a parent site.
Operation Complete.
Would this also delete permissions of the user from libraries, lists and listitems in the site, assuming that the permission inheritance is broken in the library, list or listitem?
ReplyDeleteNo, but the functionality could be added in
ReplyDeleteDid you ever add the functionality to delete a user from all lists and libraries?
DeleteHow can I add this functionalty?
DeleteGreat Article
DeleteCyber Security Projects for CSE Students
JavaScript Training in Chennai
Project Centers in Chennai
JavaScript Training in Chennai
Thanks Phil!! I was actually looking for this. You saved me a lot of time.
ReplyDeleteI like what you guys are up too.Such intelligent work and reporting!Keep up the excellent works guys I have incorporated.
ReplyDeleteSharePoint Online Training
2015-12-7 xiaozhengm
ReplyDeletefitflops clearance
michael kors uk
tory burch outlet
oakley sunglasses
nike outlet
louis vuitton outlet
louis vuitton pas cher
kate spade outlet
gucci outlet
coach outlet
michael kors outlet
canada goose uk
coach factory outlet
christian louboutin shoes
nike blazer
jordan 8s
michael kors handbags
jordan 3 infrared
caoch outlet
true religion outlet
air jordan uk
michael kors
longchamp outlet
adidas shoes uk
coach factory outlet
coach factory outlet
nike blazers
ugg australia
nike uk
coach factory outlet
tiffany and co
basketball shoes
michael kors outlet uk
louboutin
air jordans
chaussure louboutin
air jordan 13
ugg outlet
louis vuitton outlet
Great Article..
ReplyDeleteOnline DotNet Training
.Net Online Training
Dot Net Training in Chennai
IT Training in Chennai
louis vuitton
ReplyDeletecoach factory outlet
ray ban sunglasses outlet
coach factory outlet
rolex submariner watches
louis vuitton handbags
louis vuitton outlet
toms outlet
jordans
ray ban sunglasses
ralph lauren polo
cartier watches
oakley sunglasses
rolex watches
louis vuitton handbags
pandora jewelry
ralph lauren uk
true religion jeans
ray ban sunglasses
burberry outlet
jordan 3 infrared
cheap jordans
michael kors handbags
fitflops
coach outlet online
cheap ray ban sunglasses
abercrombie outlet
louis vuitton outlet
basketball shoes
jordan shoes
longchamp handbags
michael kors handbags
true religion outlet
burberry outlet online
michael kors handbags
adidas trainers
adidas originals
abercrombie and fitch
adidas outlet
tods shoes
20168.8wengdongdong
new balance shoes
ReplyDeletelouis vuitton
louis vuitton outlet
north face jackets
ysl outlet
prada sunglasses
lacoste pas cher
michael kors handbags
oakley sunglasses
michael kors clearance
chanyuan10.11
cheap ugg boots
ReplyDeleteugg boots outlet
jordan femme pas cher
patriots jerseys
beats headphones
ugg australia
michael kors outlet online
cheap rolex watches
true religion jeans
ray ban wayfarer
2016.11.26xukaimin
jordan femme
ReplyDeletecoach factory outlet
chaussures louboutin
louis vuitton handbags
christian louboutin outlet
hollister clothing
red bottoms
ugg boots
kobe bryant shoes
san antonio spurs jerseys
20173.9chenjinyan
true religion uk
ReplyDeletethunder jerseys
hollister co
nike air max 95
red bottom
toms
michael kors bags
nike roshe one
air max
coach factory outlet
0324shizhong
adidas outlet
ReplyDeletenike air max
adidas yeezy boost 350 v2
polo ralph lauren outlet
michael kors bags
christian louboutin shoes
kd 7 shoes
adidas nmd xr1
prada handbags
oakley sunglasses
2017.5.15chenlixiang
ReplyDeleteشركات الشحن جده مصر
شركات الشحن بجده لمصر
شركات الشحن مكه مصر
شركات الشحن جده لمصر
شركات الشحن مكه لمصر
شركة شحن بجده لمصر
شركات الشحن الرياض مصر
شركة شحن الرياض مصر
شركات الشحن
شركات الشحن الدولي
شركات شحن من الرياض لمصر
شركات الشحن الدولي
شركات شحن من الرياض لمصر
اسعار شركات الشحن
افضل شركة شحن
ارخص شركة شحن
شركات شحن لمصر بالرياض
شركات شحن بالرياض
شحن لمصر من الباب للباب
مكتب شحن لمصر
شحن لمصر
اسعار الشحن لمصر
Hey Thanks for your script, it helped me to get part of my requirement. But I also looking for a functionality where I am able to delete a group only for particular sub-site.
ReplyDeleteIf there are 3 sub-sites and I am deleting a group(which is present in all 3 sub-site) from one sub-site,I should be able to delete it using powershell.
Thank Had to share information, success for all
ReplyDeleteCara Ampuh Obati Penyakit Fatty Liver
Khasiat Dan Manfaat Teripang
Penyakit Gagal Ginjal
Cara Mengangkat Sel TUmor
Cara Mengatasi Biang Keringat Pada Anak
Obat Asam Lambung
This information is very useful. thank you for sharing. and I will also share information about health through the website
ReplyDeleteCara Menghilangkan Bruntusan
Obat Penyakit Susah Kencing
Cara Mengobati Gondok Beracun
Cara Mengobati Gabagen
Cara Mudah Mengobati Diabetes
Cara Mengobati Gusi Bengkak
pandora charms
ReplyDeletered bottoms louboutin
kobe 12
north face uk
valentino outlet
red bottom shoes}
nike factory
fitflop
cheap soccer cleats
supreme hoodie
3、
ReplyDeletechristian louboutin
birkenstock outlet
ferragamo outlet
fitflops sale clearance
reebok shoes
adidas outlet online
cheap jordans
coach outlet
ferragamo shoes
mowang05-27
Basically uploading the offer, You are investing buy this kind of article from owner if you're the obtaining victory in prospective buyer. You read and sign the worldwide supply support fine print breaks in the right windows nicely bill. Importance fees once estimated become short sale change even ought to growth you top say amount of money..
ReplyDeleteTimes distributing your own offer, You are Camisetas De Futbol Baratas investing buy which solution from the owner if you are the profiting prospective resultados de futbol buyer. You read and agree equipement foot with the worldwide supply system fine print frees in a unique window case or a bill. Signific allegations already offered tend to be be maillot foot 2018 more responsive to change if you amazon müller trikot decide to accelerate you optimal put money on cash..
In my amount of money usually comes maillot de foot pas cher with pertinent traditions tasks, dfb trikot müller Income income tax, Brokerage Maglie Poco Prezzo house and various Maglie Da Calcio a Poco Prezzo service expenses. Doing this important quantity is short sale change before you make payment amount. The local surf forecast in an european union male call express in any case uk, leeds, Transfer cask on our choose manuel neuer trikot rot certainly not recoverable.
So what's a check getting the money for framework? Fundamentally, it is a sort of exchange in which clients can approach the administrations offered by the bank as a check issued and approved by the bank itself. Check Cashing chicago
ReplyDeletethe website you manage is very good and in my opinion this is the best wesbite
ReplyDeletecara menyembuhkan tipes
obat polip hidung
cara menghilangkan darah kotor
cara menghilangkan amandel
obat gabagen
maillot de foot pas cher
ReplyDeletemaillot paris 2018
maillot de foot pas cher
Maillot Foot Pas Cher
maillot foot pas cher
maillot psg pas cher
maillot de foot pas cher
louboutin pas cher
louboutin soldes
شركة نقل اثاث بالرياض
ReplyDeleteشركة نقل عفش بالمدينة المنورة
شركة نقل عفش بجدة
شركة نقل عفش بالدمام
شركة تنظيف بالبخار بجدة
شركة تنظيف خزانات بجدة
Thanks please share this information if you are face any problem in Toshiba laptop. We will help you for more detail visit here
ReplyDeletecara menghilangkan jerawat beruntusan
cara mengobati luka bernanah
cara menghilangkan benjolan pada anus
cara mengobati ispa
cara menghilangkan bekas cacar
obat benjolan di kaki
https://myserviceshome.com/cleaning-houses-in-medina/
ReplyDeletehttps://myserviceshome.com/anti-bed-bugs/
https://myserviceshome.com/best-colors-bedrooms-modern/
https://myserviceshome.com/cleaning-apartments-in-jazan
https://myserviceshome.com/moving-furniture-in-jazan/
Hopefully, sustenance will be easy and simplified in all matters
ReplyDeleteObat Borok Bernanah
Cara Mengobati Lymphadenitis
Cara Menghilangkan Sekelan
I am happy to be here and this wonderful article. I have found here lots of interesting information for my knowledge I need. all the details you provide to us, it was very helpful and useful, thanks for sharing this amazing post.
ReplyDeleteobat benjolan di selangkangan
khasiat obat herbal
Cara menormalkan penglihatan yang buram
Obat herbal penyakit kulit
obat kejang kejang epilepsi
cara menghilangkan cairan di paru paru
obat benjolan
toko obat herbal
Penyebab kelebihan sel darah putih
This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine
ReplyDeletepenyebab sakit pinggang
obat penyakit mata glaukoma
obat gagal ginjal
obat penebalan dinding rahim
Thanks for sharing the info, keep up the good work going.... I really enjoyed exploring your site. obat leukosit tinggi
ReplyDeleteHopefully, sustenance will be easy and simplified in all matters :-)
ReplyDeleteOBAT LUKA BAKAR ALAMI
cara mengobati hidrosalping
cara mengobati selulit
cara mengobati penipisan lapisan otak
Hopefully, sustenance will be easy and simplified in all matters :-)
ReplyDeleteDISTRIBUTOR QNC JELLY GAMAT
Cara menumbuhkan sel kulit baru
obat kantung mata hitam
cara mengatasi saraf tulang belakang
obat radang tulang belakang
Article very interisting, thanks for sharing information
ReplyDeleteTips Mengobati Bidai Tulang Kering
6 Racikan Alami Untuk Mengobati Sakit Tumit
Cara Alami Mengobati Flek Paru-Paru
Pengobatan Alami Hilangkan Benjolan Di Tubuh
Cara Efektif Mengobati Kaki Keseleo
Tips Untuk Mengobati Kencing Batu
I am happy to be here and this wonderful article. I have found here lots of interesting information for my knowledge I need. all the details you provide to us, it was very helpful and useful, thanks for sharing this post.
ReplyDeletekhasiat obat herbal
Obat herbal penyakit kulit
obat benjolan
toko obat herbal
obat gondok beracun
risa herbal
This article is very interesting and very understandable to read. sorry beforehand, please let me share this article
ReplyDeleteCara Mudah Mengobati Prurigo
Biaya Operasi Benjolan Di Leher Akibat Kelenjar Getah Bening
Cara Mengobati Cacar Air Agar Cepat Kering Dan Sembuh Tanpa Bekas
Cara Mengatasi Nyeri Ulu Hati Dan Perut Kembung Yang Terbukti Ampuh
I can only express a word of thanks. Because with the content on this blog I can add knowledge I, thank has been sharing this information. Do not forget to visit our website to share information and knowledge about health.
ReplyDeleteCara Mengobati Keringat dingin
Obat Keringat Dingin Herbal
cheap nfl jerseys
ReplyDeletecheap jerseys
cheap jerseys from china
wholesale jerseys
cheap nfl jerseys from china
china jerseys
nfl jerseys china
wholesale nfl jerseys
cheap authentic nfl jerseys
cheap jerseys online
cheap authentic jerseys
cheap sports jerseys
cheap wholesale jerseys
china wholesale jerseys
discount nfl jerseys
cheap authentic jerseys from china
discount jerseys
custom cowboys jersey
nfl jerseys cheap
cheap nfl jerseys china
authentic nfl jerseys
camisetas de futbol
ReplyDeletecamisetas de futbol baratas
camisetas futbol baratas
camiseta real madrid barata
equipaciones de futbol baratas
comprar camisetas de futbol
camisetas de futbol baratas 2017
comprar camisetas de futbol
tiendas de futbol
camisetas de futbol
camisetas futbol baratas
camisetas futbol
camiseta real madrid barata
bounty camisetas futbol
camisetas de futbol 2018
I never imagined it would be like this in the end, everything we have been through is now gone and gone. Obat Liver Cara Mengatasi Kejang Demam Pada Anak Cara Mengatasi Batuk Disertai Sesak Pengobatan Herbal Alami
ReplyDeleteI can only express a word of thanks. Because with the content on this blog I can add knowledge I, thank has been sharing this information. Do not forget to visit our website to share information and knowledge about health.|
ReplyDeletecara mengatasi badan lemas dan pusing |
obat gondok beracun |
obat sakit pinggang |
obat sakit tulang belakang
camisetas de futbol
ReplyDeletecamisetas de futbol baratas
camisetas futbol baratas
camiseta real madrid barata
equipaciones de futbol baratas
comprar camisetas de futbol
camisetas de futbol baratas 2017
comprar camisetas de futbol
tiendas de futbol
camisetas de futbol
camisetas futbol baratas
camisetas futbol
camiseta real madrid barata
bounty camisetas futbol
camisetas de futbol 2018
I hope the information we share is useful and can be the best solution to cure your illness ... amen
ReplyDeleteObat Batuk Berdarah
Obat Jerawat Batu
Cara Mengobati Liver
Obat Luka Diabetes
Obat Tipes Anak
This is a very great post and the way you express your all post details that is too good. Thanks for sharing with us this useful post :
ReplyDeletepengobatan cacar air
manfaat sari kurma
cara mengobati batu empedu
Sharing valuable content, this is what I need to know. Thank you once again, i thanks for sharing this good content here.
ReplyDeletecara menurunkan kadar gula darah
obat gusi bengkak yang aman untuk ibu hamil
penyebab kaki bengkak pada ibu hamil
All my life just wants to be with you at all times. Throughout my life, I begged you to leave me
ReplyDeleteCara Mengobati Penyakit Batu Empedu
Cara Menurunkan Kadar Gula Darah
Obat Penyumbatan Tuba Falopi
Obat Jerawat Batu
Cara Menyembuhkan Gatal Di Penis
A beautiful purse or handbag from Coach Outlet Online can last for many years, and represent a great overall value.
ReplyDeleteThere are Michael Kors Bags Outlet in a large number of shopping malls located throughout the country.
Cheap Michael Kors Bags is a great way to determine which models best suit your needs.
Official Coach Factory Outlet Online all strive to provide comfort and convenience for their owners and the seams are double-stitched for maximum durability.
Michael Kors Factory Store, has one of the most popular handbag and accessory lines on the market today.
Coach Handbags Wholesale says a lady is classy, elegant and sophisticated.
Coach Store Near Me trends come and go, but a Coach stands the test of time.
The official Michael Kors Handbags On Sale Outlet regularly posts various handbags being offered for sale.
Compare your Coach Bags On Sale Outlet to the logo provided on the website to make sure it is similar.
All Michael Kors Outlet Online Store have serial numbers.
Thanks for provide great informatic and looking beautiful blog, really nice required information & the things i never imagined and i would request, wright more blog and blog post like that for us. Thanks you once agian
ReplyDeleteBirth certificate in delhi
Birth certificate in ghaziabad
Birth certificate in gurgaon
Birth certificate in noida
How to get birth certificate in ghaziabad
how to get birth certificate in delhi
birth certificate agent in delhi
how to download birth certificate
birth certificate in greater noida
birth certificate agent in delhi
Birth certificate delhi