PowershellScripts / SharePointOnline-ScriptSamples

Over 260 scripts for SharePoint Online (SPO), OneDrive for Business, and SharePoint Server. The samples fix issues, provide reports and extra settings not available via UI. The scripts use Powershell, C#, CSOM and REST. They include copies of existing scripts from Technet Gallery years 2013-2019. >>> Scroll down to see the full index
100 stars 37 forks source link

Great Code! how to add subsites? #198

Closed effyl01 closed 2 years ago

effyl01 commented 3 years ago

Thank you for the code. I am trying to set versioning on for a a few sites and I am reading them from a text file. All is well, but how to add so it will run on the sub-sites of those site collection as well.

foreach ($line in Get-Content c:\sites.txt) { $sitecollection=Get-SPosite $line set-Versioning -Url $sitecollection.url -Username $Username -Password $Password -Versioning $Versioning }

thanks! Effy.

PowershellScripts commented 3 years ago

Hi Effy,

For that you would need to get the subsites (and sub-subsites etc. recursively if you have multi-level structure).

Have a look if that helps: https://github.com/PowershellScripts/SharePointOnline-ScriptSamples/tree/develop/Site%20Management/Get%20all%20site%20collections%20and%20their%20subsites

If not, I can try to create a sample

effyl01 commented 3 years ago

Hi Arleta, I actually saw that code and gave it my best try and couldn't. I would very much appreciate it if you could combine the 2 scripts. I also think this will be a generic script that all site permutations can enjoy. Thanks, Effy L.

PowershellScripts commented 3 years ago

Hi Effy,

Here is a script for you: https://github.com/PowershellScripts/SharePointOnline-ScriptSamples/blob/develop/Versioning/Enable%20versions%20for%20selected%20sites%20and%20their%20subsites/Script.ps1

Let me know what you think

PowershellScripts commented 2 years ago

I am assuming @effyl01 you liked it :) since there is no response. Closing the issue