The call to CSOM RemoveSite throws an exception when trying to remove sitecollections created with modern Team Sites:
"This site belongs to a office365 group. To remove the site you've to remove the group."
SpoOperation removeSiteOperation = tenant.RemoveSite(siteCollectionUrl);
context.Load(tenant);
Is there any way to force the deletion, find the group to delete or use a new api?
We can delete the site collections created with modern team sites, we can use PnP PowerShell below to achieve it.
$credential = Get-Credential
Connect-PnPOnline https://[tenant].sharepoint.com -credential $credential
Remove-PnPTenantSite https://[tenant].sharepoint.com/sites/ModernTeamSite
And deleting the group using the PowerShell below.
$credential = Get-Credential
Connect-PnPOnline https://[tenant].sharepoint.com -credential $credential
Remove-PnPUnifiedGroup -Identity groupID // you can get group Ids from Get-PnPUnifiedGroup
Reference: Completely delete an Office365 site collection classic or modern from recycle bin
And also check the similar thread below.
Unable to remove Office 365 Group Site Collection
Related
I am currently trying to disable a OneDrive for my organisation. It works pretty well for new users, but old ones got access. I worked out one solution - when I take away collection admin rights user cannot use OneDrive anymore.
But I have 1000 users, and I will die changing permissions by hand, therefore is there any script to set all site collection admins to one person?
I mean those settings:
https://i.stack.imgur.com/A63RZ.png
If you want to disable OneDrive and don't want anyone to access it, instead of changing permissions, you can lock all OneDrive sites via PowerShell code:
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
#Parameters
$AdminCenterURL = "https://xxx-admin.sharepoint.com"
Try {
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)
#Get All OneDrive for Business Sites in the Tenant
$OneDriveSites = Get-SPOSite -Limit ALL -includepersonalsite $True -Filter "Url -like '-my.sharepoint.com/personal/'"
#Loop through each OneDrive Site
Foreach($Site in $OneDriveSites)
{
Set-SPOSite -Identity $Site -LockState "NoAccess"
Write-host "Scanning site:"$Site.Url "is locked"-f Yellow
}
}
Catch {
write-host -f Red "Error locking Sites:" $_.Exception.Message
}
Result is:
After that, when users try to access OneDrive, a 403 error will be returned.
About Set-SPOSite
Try to use SharePoint PnP to get all the sites on a SharePoint 2013 server.
From central administration, I can view all site collections as
/
/people/A
/people/B
...
The site urls are like
https://people-hr.mycompany.com
https://people-hr.mycompany.com/A/JohnAllen
https://people-hr.mycompany.com/A/SamAdams
https://people.hr.mycompany.com/B/JamesBell
...
Using
Connect-PnPOnline -Url "https://products.mycompany.com" -Credentials (Get-Credential)
or
Connect-PnPOnline -Url "https://products.mycompany.com/A/JohnAllen" -Credentials (Get-Credential)
I can get to the root site or a subsite. But there are so many sites. I need to get all the sites so I can iterate them to do some data maintenance.
I tried to use Get-PnPSite and Get-PnPSubWebs (with Recurse), but they failed to return all the sites.
Get-PnPTenantSite will return all the site collections. in order to iterate through each, Try this:
$cred = Get-Credential
Connect-PnPOnline "https://mytenant.sharepoint.com" -Credentials $cred
$SiteCollections = Get-PnPTenantSite
foreach ($SiteCollection in $SiteCollections)
{
Connect-PnPOnline -Url $SiteCollection.Url -Credentials $cred
Get-PnPSubWebs
}
You could use the command Get-PnPTenantSite to list all site collections.
Reference:
https://learn.microsoft.com/en-us/powershell/module/sharepoint-pnp/get-pnptenantsite?view=sharepoint-ps
I'm trying to link a classic site to a office 365 group in a Azure function. But I'm having problem to connect to Connect-SPOService. Do I use this correct?
$adminUrl = "https://" +$keyResponseAppTenant +"-admin.sharepoint.com"
Connect-SPOService -Url $adminUrl -Credential $cred
Set-SPOSiteOffice365Group -Site $url -DisplayName $title -Alias $title -IsPublic:$false
Error in function:
Then I probably have to add the "module"? Do I take the whole folder from "C:\Program Files\SharePoint Online Management Shell" ?
The answer is to upload "sharepoint online management shell"-files from that folder :D
I had a subsite in a site collection I wanted to transfer to another site collection (both in Sharepoint 2013). I made a site template with content out of it so I can transfer it to another site collection. I uploaded the solution and activated it. I made sure the activated features were completely identical. However, when I create a new subsite and choose to use the uploaded solution, I continue to receive a error message saying it is missing a feature called "MobileExcelWebAccess."
I have no clue where to find that feature. I literally enabled every site feature and site collection feature but I still end up with that error. I've read on other resources that it could be found on Central Admin but I don't have access there.
If I can't enable it in the new site, is there a way to disable it in my old site?
Try running this from a SharePoint 2013 Management Shell: Enable-SPFeature MobileExcelWebAccess -Url http://[replace with your url]
The simple line script from Ola Ekdahl did not work for me, but this did:
Replace the $url with your site collection url
save the script in .ps1 file
Open SharePoint Online Management Shell in Administrator mode and execute the script like .\
A prompt will be poped-up that asks your credential (Administrator) for the site collection
$url = "https://<your site collection url>"
$clientDll = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$runtimeDll = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$cred = get-credential
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.username, $cred.password)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint site: '$Url'" -ForegroundColor Green
}
$clientContext.Site.Features.Add('e995e28b-9ba8-4668-9933-cf5c146d7a9f',$true,[Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$clientContext.ExecuteQuery()
source: http://mahedevelopment.blogspot.gr/2016/07/sharepoint-online-mobileexcelwebaccess.html
I am trying to create a new web application using PowerShell. I keep getting the error application pool account is not found! How do I solve this?
I tried adding the new web application to DefaultAppPool as follows:
New-SPWebApplication -Name "Test WebApp" -ApplicationPool "DefaultAppPool" -ApplicationPoolAccount (Get-SPManagedAccount "WIN2K8R2SPTEST\Administrator")
But the Cmdlet Get-SPManagedAccount seems to return an empty string. I also tried to change the ApplicationPool to SharePoint 80.
I am running SharePoint Foundation 2010 on a standalone installation. How can I fix this error?
You must create a managed account first for your win2k8r2sptest\administrator. Here is the sequence of steps
$cred = get-credential 'win2k8r2sptest\administrator' // enter the password here
$adminMA = New-SPManagedAccount -Credential $cred
New-SPWebApplication -Name 'Test Webapp' -ApplicationPool "DefaultAppPool" -ApplicationPoolAccount $adminMA
I've tested this on vanilla SPS2010 SP1. I think the process is identical to Foundation as well.
In my case I already have the script as posted above by #romanrozinov. But it still didn't work. I realized I have to create a user account in the AD users. Steps can be followed here - http://www.mustbegeek.com/create-user-account-in-windows-server-2008-r2/
I'm an absolute beginner with Sharepoint, adding a user and then running below script fixed the issue:
$cred = get-credential //enter user name and password
$devAccount = New-SPManagedAccount -Credential $cred
New-SPWebApplication -Name 'Test Webapp' -ApplicationPool "DefaultAppPool" -
ApplicationPoolAccount $devAccount