sharepoint0520
asked on
How to remove Primary and Secondary Site Collection Admin by powershell script?
Hi,
We have sharepoint farm with more site collections. We have to remove Primary and Secondary admin from site collection. We have big excel file. I need your help for best approach and the powershell script to remove Primary and Secondary site admin.
Site-Admins.xlsx
We have sharepoint farm with more site collections. We have to remove Primary and Secondary admin from site collection. We have big excel file. I need your help for best approach and the powershell script to remove Primary and Secondary site admin.
Site-Admins.xlsx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, the script will replace primary site collection admin (if you uncomment 'New-SPUser ' line). Secondary admin is not necessary
ASKER
Hi,
I am really sorry but i am having problem to run this script. I think i have to come up with different approach. I have a list of 10 users and i have to replace that user with SerivceAccount
Replace_Site_User.csv
Here is the code i have used to get the report for Primary and Secondary owner and additional owners.
I am really sorry but i am having problem to run this script. I think i have to come up with different approach. I have a list of 10 users and i have to replace that user with SerivceAccount
Replace_Site_User.csv
Here is the code i have used to get the report for Primary and Secondary owner and additional owners.
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$webapp = "http://webApp/"
$Web = Get-SPWebApplication $webapp
$text = ""
$text | out-file $outputFile
foreach ($sites in $Web.sites) {
<#$text = "-------------------------------------------"
$text | out-file $outputFile -append
$text = "Site: " + $sites.url
$text | out-file $outputFile -append
$text = "Primary Owner: " + $sites.owner.Name
$text | out-file "$outputfile" -append
$text = "Secondary Owner: " + $sites.secondarycontact.Name
$text | out-file "$outputfile" -append
$text = "-------------------------------------------"
$text | out-file "$outputfile" -append#>
$addlOwners = $sites.RootWeb.SiteAdministrators
$owners = ""
foreach($owner in $addlOwners)
{
$owners += $owner.Name + ";"
}
"$($sites.url),$($sites.owner.Name),$($sites.secondarycontact.Name),$($owners)" | Out-File C:\SiteOwnerReport.csv -Append
$sites.url
}
Write-Host "Completed"
ASKER
Thank you for the response. You mean i can not remove site collection Admin from site collection. So site collection must have primary and secondary admin. In that case i have replace those users with farm admin.
Is this your script will work to replace it?
Site-Admins-CSV.csv