diff --git a/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/description.md b/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/description.md index a0d6f92d..fdc22124 100644 --- a/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/description.md +++ b/Content Types/Content Types Management Setting/Allow content type management for all lists in a site/description.md @@ -22,9 +22,9 @@ $Url="https://trialtrial123.sharepoint.com/sites/teamsitewithlists" $ContentTypesEnabled=$true ``` -###Please share your thoughts in the Q&A section! +### Please share your thoughts in the Q&A section! -####Related scripts
+#### Related scripts
[Set direction of the reading order for a single list](https://gallery.technet.microsoft.com/office/Set-SPOList-properties-9d16f2ba) [Set-SPOList properties (module)](https://gallery.technet.microsoft.com/scriptcenter/Disable-or-enable-12cf3795) diff --git a/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/ContentTypeManagementSubsitesIncluded.ps1 b/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/ContentTypeManagementSubsitesIncluded.ps1 index 9e762df4..71ad751b 100644 --- a/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/ContentTypeManagementSubsitesIncluded.ps1 +++ b/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/ContentTypeManagementSubsitesIncluded.ps1 @@ -3,61 +3,52 @@ # Created by Arleta Wanat, 2015 # -function Set-SPOListsContentTypesEnabled -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOListsContentTypesEnabled{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [bool]$ContentTypesEnabled -) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.ExecuteQuery() - -$Lists=$ctx.Web.Lists - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) -$ctx.Load($Lists) -$ctx.ExecuteQuery() - -Foreach($ll in $Lists) -{ - $ll.ContentTypesEnabled = $ContentTypesEnabled - $ll.Update() - - - try - { - $ctx.ExecuteQuery() - Write-Host $ll.Title " Done" -ForegroundColor Green - } - - catch [Net.WebException] - { - - Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red - } + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.ExecuteQuery() + + $Lists=$ctx.Web.Lists + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $ctx.Load($Lists) + $ctx.ExecuteQuery() + + Foreach($ll in $Lists){ + $ll.ContentTypesEnabled = $ContentTypesEnabled + $ll.Update() + + try{ + $ctx.ExecuteQuery() + Write-Host $ll.Title " Done" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red + } + } + + if($ctx.Web.Webs.Count -gt 0){ + Write-Host "--"-ForegroundColor DarkGreen + + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled + } + } } -if($ctx.Web.Webs.Count -gt 0) - { - Write-Host "--"-ForegroundColor DarkGreen - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - Set-SPOListsContentTypesEnabled -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -ContentTypesEnabled $ContentTypesEnabled - } - } - -} - @@ -80,4 +71,4 @@ $ContentTypesEnabled=$true -Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled \ No newline at end of file +Set-SPOListsContentTypesEnabled -Username $Username -AdminPassword $AdminPassword -Url $Url -ContentTypesEnabled $ContentTypesEnabled diff --git a/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/description.md b/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/description.md index bc34af8c..eec2be23 100644 --- a/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/description.md +++ b/Content Types/Content Types Management Setting/Allow content type management for all lists in site collection/description.md @@ -1,29 +1,17 @@ A short Powershell script to allow management of content types for all SharePoint Online lists and libraries across all sites in a site collection - - -It is an equivalent of List>>List Settings>>Advanced>>Content types in Graphic User Interface (see screenshot) - - - - - - +It is an equivalent of **List**>>**List Settings**>>**Advanced**>>**Content types in Graphic User Interface** ([see screenshot](https://github.com/PowershellScripts/AllGalleryScriptsSamples/blob/develop/Content%20Types/Content%20Types%20Management%20Setting/Allow%20content%20type%20management%20for%20all%20lists%20in%20site%20collection/contentTypeManagement.png)) Applies to lists and libraries. - - -It requires installed SharePoint Online SDK +*It requires installed* [SharePoint Online SDK](www.microsoft.com/en-us/download/details.aspx?id=42038) You have to enter the list information before running the script: - - ```PowerShell # Paths to SDK. Please verify location on your computer. @@ -36,33 +24,26 @@ $AdminPassword="Pass" $Url="https://trialtrial123.sharepoint.com/sites/teamsitewithlists" $ContentTypesEnabled=$true ``` - - - - - -Please share your thoughts in the Q&A section! - - +### Please share your thoughts in the Q&A section! -Wiki article with detailed code description: +#### Wiki article with detailed code description: [SharePoint Online: Turn on support for multiple content types in a list or library using Powershell](http://social.technet.microsoft.com/wiki/contents/articles/30038.sharepoint-online-turn-on-support-for-multiple-content-types-in-a-list-or-library-using-powershell.aspx) -Related scripts -Set-SPOList properties (module) +#### Related scripts +[Set-SPOList properties (module)](https://gallery.technet.microsoft.com/office/Set-SPOList-properties-9d16f2ba) -Disable or enable attachments to list items using Powershell +[Disable or enable attachments to list items using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Disable-or-enable-12cf3795) -Change search setting for all lists in a site using CSOM and Powershell +[Change search setting for all lists in a site using CSOM and Powershell](https://gallery.technet.microsoft.com/scriptcenter/Change-search-setting-for-8e842a48) -Allow content type management for all lists in a site using Powershell +[Allow content type management for all lists in a site using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Allow-content-type-5bca5157) -Set content type management setting for SharePoint Online list using Powershell +[Set content type management setting for SharePoint Online list using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Set-content-type-39ae4bce)

diff --git a/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 b/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 index db6603cf..a18ba4af 100644 --- a/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 +++ b/Content Types/Content Types Management Setting/Set content type management setting for a single list/ListContentTypes.ps1 @@ -3,58 +3,45 @@ # Created by Arleta Wanat, 2015 # -function Set-SPOList -{ -param ( - [Parameter(Mandatory=$true,Position=0)] +function Set-SPOList{ + param( + [Parameter(Mandatory=$true,Position=0)] [string]$ListName, - [Parameter(Mandatory=$true,Position=1)] + [Parameter(Mandatory=$true,Position=1)] [bool]$ContentTypesEnabled - ) + ) -$ll=$ctx.Web.Lists.GetByTitle($ListName) + $ll=$ctx.Web.Lists.GetByTitle($ListName) -$ll.ContentTypesEnabled = $ContentTypesEnabled - $ll.Update() - - try - { - $ctx.ExecuteQuery() - Write-Host "Done" -ForegroundColor Green - } - - catch [Net.WebException] - { - - Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red - } - + $ll.ContentTypesEnabled = $ContentTypesEnabled + $ll.Update() + try{ + $ctx.ExecuteQuery() + Write-Host "Done" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red + } } - - - -function Connect-SPOCSOM -{ - param ( - [Parameter(Mandatory=$true,Position=1)] +function Connect-SPOCSOM{ + param( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$AdminPassword, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] [string]$Url -) + ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.ExecuteQuery() -$global:ctx=$ctx + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.ExecuteQuery() + $global:ctx=$ctx } - $global:ctx @@ -77,4 +64,4 @@ $ContentTypesEnabled =$false Connect-SPOCSOM -Username $Username -AdminPassword $AdminPassword -Url $Url -Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled \ No newline at end of file +Set-SPOList -ListName $ListName -ContentTypesEnabled $ContentTypesEnabled diff --git a/Content Types/Create/Add Content Type to Lists with Workflows/description.md b/Content Types/Create/Add Content Type to Lists with Workflows/description.md index 29aee1dd..b97da707 100644 --- a/Content Types/Create/Add Content Type to Lists with Workflows/description.md +++ b/Content Types/Create/Add Content Type to Lists with Workflows/description.md @@ -9,11 +9,9 @@ http://social.technet.microsoft.com/wiki/contents/articles/31051.sharepoint-onli ### How to use? +1. Download and install [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038). - -1. Download and install SharePoint Online SDK. - -2. Download the .ps1 file. +2. Download the *.ps1* file. 3. Open the file (you can do it also in NotePad) @@ -33,15 +31,14 @@ $Name="Name of the Content Type2" $ParentContentTypeID="0x01" $Group="List Content Types" ``` -a) Find on your computer where SharePoint.Clitent.dll and SharePoint.Client.Runtime.dll libraries are located and insert the correct paths -b) Instead of "admin@tenant.onmicrosoft.com" enter you username -c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to find the content types -d) Fill in the properties of the content type. +a) Find on your computer where SharePoint.Clitent.dll and SharePoint.Client.Runtime.dll libraries are located and insert the correct paths
+b) Instead of "admin@tenant.onmicrosoft.com" enter you username
+c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to find the content types
+d) Fill in the properties of the content type.
- 5. Run the script in Powershell (any module). -6. When the script has executed, Powershell will show a message Content Type Name of the Content Type2 has been added to Title of the List. +6. When the script has executed, Powershell will show a message *Content Type Name of the Content Type2 has been added to Title of the List*.

Enjoy and please share feedback! diff --git a/Content Types/Get/Get Names of all content types added to your lists/GetCTNamesinAllLists.ps1 b/Content Types/Get/Get Names of all content types added to your lists/GetCTNamesinAllLists.ps1 index d5c99a27..45c10140 100644 --- a/Content Types/Get/Get Names of all content types added to your lists/GetCTNamesinAllLists.ps1 +++ b/Content Types/Get/Get Names of all content types added to your lists/GetCTNamesinAllLists.ps1 @@ -1,64 +1,41 @@ - - -function Get-SPOList -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SPOList{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web.Lists) - $ctx.ExecuteQuery() - Write-Host - Write-Host $ctx.Url -BackgroundColor White -ForegroundColor DarkGreen - foreach( $ll in $ctx.Web.Lists) - { + ) - $ctx.Load($ll.ContentTypes) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() - try - { - $ctx.ExecuteQuery() - } - catch - { - } + $ctx.Load($ctx.Web.Lists) + $ctx.ExecuteQuery() + Write-Host + Write-Host $ctx.Url -BackgroundColor White -ForegroundColor DarkGreen + foreach( $ll in $ctx.Web.Lists){ + $ctx.Load($ll.ContentTypes) - + try{ + $ctx.ExecuteQuery() + } + catch{ + } - Write-Host $ll.Title -ForegroundColor Green - - foreach($cc in $ll.ContentTypes) - { - Write-Output $cc.Name - } + Write-Host $ll.Title -ForegroundColor Green - - + foreach($cc in $ll.ContentTypes){ + Write-Output $cc.Name + } - - - } - - - - } - - - - - + } +} + # Paths to SDK. Please verify location on your computer. @@ -71,4 +48,4 @@ $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://tenant.sharepoint.com/sites/teamsitewithlibraries" -Get-SPOList -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl \ No newline at end of file +Get-SPOList -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl diff --git a/Items Management/Attachments/Enable or disable attachments to items of a chosen list/ListAttachments.ps1 b/Items Management/Attachments/Enable or disable attachments to items of a chosen list/ListAttachments.ps1 index 275e2759..874aabc2 100644 --- a/Items Management/Attachments/Enable or disable attachments to items of a chosen list/ListAttachments.ps1 +++ b/Items Management/Attachments/Enable or disable attachments to items of a chosen list/ListAttachments.ps1 @@ -1,57 +1,49 @@ - + # # Created by Arleta Wanat, 2015 # -function Set-SPOList -{ -param ( +function Set-SPOList{ + param ( [Parameter(Mandatory=$true,Position=0)] - [string]$ListName, + [string]$ListName, [Parameter(Mandatory=$true,Position=1)] - [bool]$Attachments - ) + [bool]$Attachments + ) -$ll=$ctx.Web.Lists.GetByTitle($ListName) + $ll=$ctx.Web.Lists.GetByTitle($ListName) -$ll.EnableAttachments = $Attachments - $ll.Update() + $ll.EnableAttachments = $Attachments + $ll.Update() - try - { + try{ $ctx.ExecuteQuery() Write-Host "Done" -ForegroundColor Green - } - - catch [Net.WebException] - { - - Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red - } - - + } + catch [Net.WebException] { + Write-Host "Failed" $_.Exception.ToString() -ForegroundColor Red + } } -function Connect-SPOCSOM -{ - param ( - [Parameter(Mandatory=$true,Position=1)] +function Connect-SPOCSOM{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$AdminPassword, [Parameter(Mandatory=$true,Position=2)] [string]$Url -) + ) -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) $ctx.ExecuteQuery() -$global:ctx=$ctx + $global:ctx=$ctx } @@ -78,4 +70,4 @@ $Attachments =$true Connect-SPOCSOM -Username $Username -AdminPassword $AdminPassword -Url $Url -Set-SPOList -ListName $ListName -Attachments $Attachments \ No newline at end of file +Set-SPOList -ListName $ListName -Attachments $Attachments diff --git a/Items Management/Attachments/Enable or disable attachments to items of a chosen list/description.md b/Items Management/Attachments/Enable or disable attachments to items of a chosen list/description.md index e17f799d..ae4331ff 100644 --- a/Items Management/Attachments/Enable or disable attachments to items of a chosen list/description.md +++ b/Items Management/Attachments/Enable or disable attachments to items of a chosen list/description.md @@ -1,22 +1,10 @@ -A short Powershell script to set the EnableAttachments property for a SharePoint Online list. The property is responsible for the Attach File icon under new item tab. If you disable the button, you and your users will not be able to add the attachments to list items. +A short Powershell script to set the EnableAttachments property for a SharePoint Online list. The property is responsible for the **Attach File** icon under **new item** tab. If you disable the button, you and your users will not be able to add the attachments to list items. -A short Powershell script to set the EnableAttachments property for a SharePoint Online list. The property is responsible for the Attach File icon under new item tab (see screenshot). The button allows you to add attachments to the list item. - - - - - - - - + If you disable the button, you and your users will not be able to add the attachments to list items: - - - - - + Applies to lists. @@ -24,7 +12,7 @@ Applies to lists. -It requires installed SharePoint Online SDK +It requires installed [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038) You have to enter the list information before running the script: @@ -45,18 +33,14 @@ $ListName="Tasks list" $Attachments =$false ``` -### Related scripts -Set direction of the reading order for a single list +## **Related scripts** +[Set direction of the reading order for a single list](https://gallery.technet.microsoft.com/office/Set-the-direction-of-the-f17ca66a) -Set-SPOList properties (module) - - - - +[Set-SPOList properties (module)](https://gallery.technet.microsoft.com/office/Set-SPOList-properties-9d16f2ba) -### Related article +## **Related article** -SharePoint Online: Disable or enable attachments to list items using Powershell +[SharePoint Online: Disable or enable attachments to list items using Powershell](https://social.technet.microsoft.com/wiki/contents/articles/30024.sharepoint-online-disable-or-enable-attachments-to-list-items-using-powershell.aspx)

diff --git a/Site Management/Add Supported Language for multiple site collections/SetLGforAllSites.ps1 b/Site Management/Add Supported Language for multiple site collections/SetLGforAllSites.ps1 index 8ef75a4f..1505a02b 100644 --- a/Site Management/Add Supported Language for multiple site collections/SetLGforAllSites.ps1 +++ b/Site Management/Add Supported Language for multiple site collections/SetLGforAllSites.ps1 @@ -1,37 +1,35 @@  -function Add-SPOUILanguages -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Add-SPOUILanguages{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [Int]$lcid - ) + ) - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() - Write-Host $ctx.Web.Url - $ctx.Web.IsMultilingual=$true - $ctx.Web.Update() - $ctx.ExecuteQuery() - $ctx.Web.AddSupportedUILanguage($lcid) - - $ctx.Web.Update() - + Write-Host $ctx.Web.Url + $ctx.Web.IsMultilingual=$true + $ctx.Web.Update() + $ctx.ExecuteQuery() + $ctx.Web.AddSupportedUILanguage($lcid) -$ctx.ExecuteQuery() - - $ctx.Dispose() + $ctx.Web.Update() + + + $ctx.ExecuteQuery() + + $ctx.Dispose() } @@ -52,8 +50,6 @@ Connect-SPOService $adminUrl -Credential $Username $sites=(get-spoSite).Url -foreach($site in $sites) -{ - -Add-SPOUILanguages -Username $Username -AdminPassword $AdminPassword -Url $site -lcid $lcid -} \ No newline at end of file +foreach($site in $sites){ + Add-SPOUILanguages -Username $Username -AdminPassword $AdminPassword -Url $site -lcid $lcid +} diff --git a/Site Management/Add Supported Language for multiple site collections/description.md b/Site Management/Add Supported Language for multiple site collections/description.md index 66d0c1b2..f8056073 100644 --- a/Site Management/Add Supported Language for multiple site collections/description.md +++ b/Site Management/Add Supported Language for multiple site collections/description.md @@ -1,8 +1,10 @@ The script adds a supported language to all site collections. -1. It retrieves the urls using Get-SPOSite. -2. It loops through the urls. -3. For each specified url, it adds a supported language. +**1.** It retrieves the urls using Get-SPOSite. + +**2.** It loops through the urls. + +**3.** For each specified url, it adds a supported language. Make sure the script is using correct paths to the SDK libraries on your machine: @@ -22,22 +24,22 @@ $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $adminUrl="https://tenant-admin.sharepoint.com" $lcid=1031 ``` -$lcid refers to Locale ID. A list of Microsoft-assigned locale ids can be found here:https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx +$lcid refers to Locale ID. A list of Microsoft-assigned locale ids can be found [here](https://msdn.microsoft.com/en-us/goglobal/bb964664.aspx). ### The script can be modified. -1. If you want to add language only for a few site collections/subsites, enter the urls in the line below instead of Get-SPOSite cmdlet: +**1.** If you want to add language only for a few site collections/subsites, enter the urls in the line below instead of Get-SPOSite cmdlet: ```PowerShell $sites=(get-spoSite).Url ``` - 2. If you want to add 2 or more languages, enter more AddSupportedUILanguage() methods: +**2.** If you want to add 2 or more languages, enter more AddSupportedUILanguage() methods: ```PowerShell $ctx.Web.AddSupportedUILanguage($lcid) ``` - 3. If you want to remove a language instead of adding it, modify the following line: +**3.** If you want to remove a language instead of adding it, modify the following line: ```PowerShell $ctx.Web.AddSupportedUILanguage($lcid) ``` @@ -46,8 +48,7 @@ into: $ctx.Web.RemoveSupportedUILanguage($lcid) ``` - 4. If you need to assign administrator's permissions to ODB, you can use the following script: - http://sharepoint.stackexchange.com/questions/138562/add-personal-site-collection-administrator-programmatically +**4.** If you need to assign administrator's permissions to ODB, you can use the following [script](http://sharepoint.stackexchange.com/questions/138562/add-personal-site-collection-administrator-programmatically).

diff --git a/Site Management/Add-SPOWeb & Remove-SPOWeb/RemoveANDAddSPOWeb1.psm1 b/Site Management/Add-SPOWeb & Remove-SPOWeb/RemoveANDAddSPOWeb1.psm1 index 7544eacd..e200d5ce 100644 --- a/Site Management/Add-SPOWeb & Remove-SPOWeb/RemoveANDAddSPOWeb1.psm1 +++ b/Site Management/Add-SPOWeb & Remove-SPOWeb/RemoveANDAddSPOWeb1.psm1 @@ -1,117 +1,95 @@ -function Remove-SPOWeb -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Remove-SPOWeb{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword, - [Parameter(Mandatory=$false,Position=4)] + [Parameter(Mandatory=$false,Position=4)] [bool]$RemoveSubsites=$true - ) - - $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) - $ctx.ExecuteQuery() - - try - { - $ctx.Web.DeleteObject() - $ctx.ExecuteQuery() - Write-Host "Site " $ctx.Web.Url " has been removed." - } - catch [Net.WebException] - { - Write-Host $_.Exception.ToString() - } - -if($ctx.Web.Webs.Count -gt 0) - { - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - if($RemoveSubsites) - { - Remove-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -RemoveSubsites $RemoveSubsites - } - - else - { - $yesorno=Read-Host -Prompt "Proceeding to remove subsite " $ctx.Web.Webs[$i].Url ". Press Y to proceed or N not to remove the subsite. If you choose N, the parent site won't be removed." - if($yesorno -eq "y") - { - Remove-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -RemoveSubsites $RemoveSubsites - } - } - } - } - - - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + + try{ + $ctx.Web.DeleteObject() + $ctx.ExecuteQuery() + Write-Host "Site " $ctx.Web.Url " has been removed." + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } + + if($ctx.Web.Webs.Count -gt 0){ + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + if($RemoveSubsites){ + Remove-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -RemoveSubsites $RemoveSubsites + } + else{ + $yesorno=Read-Host -Prompt "Proceeding to remove subsite " $ctx.Web.Webs[$i].Url ". Press Y to proceed or N not to remove the subsite. If you choose N, the parent site won't be removed." + if($yesorno -eq "y"){ + Remove-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -RemoveSubsites $RemoveSubsites + } + } + } + } } -function Add-SPOWeb -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Add-SPOWeb{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$ParentSiteUrl, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$Title, - [Parameter(Mandatory=$false,Position=5)] + [Parameter(Mandatory=$false,Position=5)] [bool]$UseSamePermissionsAsParentSite=$true, - [Parameter(Mandatory=$false,Position=6)] + [Parameter(Mandatory=$false,Position=6)] [string]$Description="", - [Parameter(Mandatory=$true,Position=7)] + [Parameter(Mandatory=$true,Position=7)] [Int]$Language, - [Parameter(Mandatory=$true,Position=8)] + [Parameter(Mandatory=$true,Position=8)] [string]$Url, - [Parameter(Mandatory=$false,Position=9)] + [Parameter(Mandatory=$false,Position=9)] [string]$WebTemplate="STS#0" - ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($ParentSiteUrl) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) - $ctx.ExecuteQuery() - - - $wci = New-Object Microsoft.SharePoint.Client.WebCreationInformation - $wci.Title=$Title - $wci.Description=$Description - $wci.Language = $Language - $wci.Url =$Url - $wci.WebTemplate = $WebTemplate - $wci.UseSamePermissionsAsParentSite=$UseSamePermissionsAsParentSite - - $SPOWeb = $ctx.Web.Webs.Add($wci) - $ctx.Load($SPOWeb) - try - { - - $ctx.ExecuteQuery() - Write-Host "Site " $SPOWeb.Title " has been added to " $ParentSiteUrl - } - catch [Net.WebException] - { - Write-Host $_.Exception.ToString() - } - - - - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($ParentSiteUrl) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + + $wci = New-Object Microsoft.SharePoint.Client.WebCreationInformation + $wci.Title=$Title + $wci.Description=$Description + $wci.Language = $Language + $wci.Url =$Url + $wci.WebTemplate = $WebTemplate + $wci.UseSamePermissionsAsParentSite=$UseSamePermissionsAsParentSite + + $SPOWeb = $ctx.Web.Webs.Add($wci) + $ctx.Load($SPOWeb) + + try{ + $ctx.ExecuteQuery() + Write-Host "Site " $SPOWeb.Title " has been added to " $ParentSiteUrl + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } } diff --git a/Site Management/Add-SPOWeb & Remove-SPOWeb/description.md b/Site Management/Add-SPOWeb & Remove-SPOWeb/description.md index cddeb915..32083f2d 100644 --- a/Site Management/Add-SPOWeb & Remove-SPOWeb/description.md +++ b/Site Management/Add-SPOWeb & Remove-SPOWeb/description.md @@ -1,51 +1,54 @@ 2 new SharePoint Online Powershell cmdlets to help you manage sites and subsites in your SharePoint Online subscription: - - -Add-SPOWeb +## Add-SPOWeb Adds a subsite to an exisiting site collection -Parameters +## *Parameters* The cmdlet is using the following parameters: - [string]$Username +- [string]$Username + The string specifies admin of the site -[string]$ParentUrl +- [string]$ParentUrl + Specifies the url of the parent site -[string]$AdminPassword, +- [string]$AdminPassword, + Admin's password -[string]$Title, +- [string]$Title, + Specifies the title of the site -[bool]$UseSamePermissionsAsParentSite=$true, +- [bool]$UseSamePermissionsAsParentSite=$true, + Whether the site should use the same permissions as parent site. By default it is set to true -[string]$Description="", +- [string]$Description="", + Site description, not mandatory -[Int]$Language, -The language of the site. For English choose 1033. For other languages choose the correct id. +- [Int]$Language, -[string]$Url, -Url of the new site, avoid spaces. +The language of the site. For English choose 1033. For other languages choose the correct [id](https://docs.microsoft.com/pl-pl/SharePoint/install/install-or-uninstall-language-packs?redirectedfrom=MSDN). -[string]$WebTemplate="STS#0" -Template of the site, e.g. teamsite, publishing portal, enterprise wiki. By default set to Teamsite template. For other template types, check here +- [string]$Url, - +Url of the new site, avoid spaces. - +- [string]$WebTemplate="STS#0" + +Template of the site, e.g. teamsite, publishing portal, enterprise wiki. By default set to Teamsite template. For other template types, check [here](https://docs.microsoft.com/pl-pl/archive/blogs/) -Remove-SPOWeb +## Remove-SPOWeb Removes a subsite from a site collection. @@ -53,27 +56,31 @@ Removes a subsite from a site collection. -Parameters +### *Parameters* The cmdlet is using the following parameters: - [string]$Username +- [string]$Username + The string specifies admin of the site -[string]$Url +- [string]$Url + Specifies the url of the site -[string]$AdminPassword, +- [string]$AdminPassword, + Admin's password -[bool]$RemoveSubsites=$true +- [bool]$RemoveSubsites=$true + If set to false, the cmdlet will ask for additional permissions if it encounters sub-sites of the site being removed. As long as one of the subsites exists, the site will never be removed. By default set to $true. -Examples +*Examples* @@ -89,31 +96,25 @@ Add-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -ParentSiteUrl https:// Remove-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -AdminPassword Pass -Url https://trialtrial123.sharepoint.com/psweb - - + +*Requirements* - - -Requirements - - - -The following libraries (SharePoint Online SDK) are required. If those libraries are in different location on your computer, please edit the .psm1 file! +The following libraries (SharePoint Online SDK) are required. If those libraries are in different location on your computer, please edit the ```.psm1``` file! -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - + ``` -Let me know about your experience in the Q&A section! +## Let me know about your experience in the Q&A section! diff --git a/Site Management/ChangeLog/Create a report on all changes for all your site collections/changecollection.ps1 b/Site Management/ChangeLog/Create a report on all changes for all your site collections/changecollection.ps1 index 34068753..0ad84c7e 100644 --- a/Site Management/ChangeLog/Create a report on all changes for all your site collections/changecollection.ps1 +++ b/Site Management/ChangeLog/Create a report on all changes for all your site collections/changecollection.ps1 @@ -1,79 +1,80 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$CSVPath - - -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ -$ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) -$changeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery $true,$true - -$changeCollection = $ctx.Site.GetChanges($changeQuery) -$ctx.Load($changeCollection) -try -{ -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url " loaded changes" -} catch [Net.WebException] - { - - Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red - -} - -foreach ($change in $changeCollection) -{ -$change | Add-Member SiteCollection($Url) -$change | Add-Member ItemName("N/A") -$change | Add-Member ListName("N/A") -$change | Add-Member WebName("N/A") -$change | Add-Member UserName("N/A") -$change | Add-Member UserTitle("N/A") - -if(! $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("N/A")} else { -$leeafyname=$ctx.Web.Lists.GetById($change.ListId).GetItemById($change.ItemId) -$ctx.Load($leeafyname) -$ctx.ExecuteQuery() -$change.ItemName=$leeafyname.LeafName} -if(! $change.IsPropertyAvailable("ListId")) { $change | Add-Member ListId("N/A")}else { -$listka=$ctx.Web.Lists.GetById($change.ListId) -$ctx.Load($listka) -$ctx.ExecuteQuery() -$change.ListName=$listka.Title} -if(! $change.IsPropertyAvailable("WebId")) { $change | Add-Member WebId("N/A")}else { $change.WebName=$ctx.Web.Url} -if(! $change.IsPropertyAvailable("UserId")) { $change | Add-Member UserId("N/A")}else { $ctx.Load($ctx.Web.GetUserById($change.UserId)) -$ctx.ExecuteQuery() -$change.UserName=$ctx.Web.GetUserById($change.UserId).LoginName -$change.UserTitle=$ctx.Web.GetUserById($change.UserId).Title} -if(! $change.IsPropertyAvailable("AlertId")) { $change | Add-Member AlertId("N/A")} -if(! $change.IsPropertyAvailable("Activate")) { $change | Add-Member Activate("N/A")} - -$change | export-csv $CSVPath -Append -} - - - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $changeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery $true,$true + + $changeCollection = $ctx.Site.GetChanges($changeQuery) + $ctx.Load($changeCollection) + + try{ + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url " loaded changes" + } + catch [Net.WebException] { + Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red + } + + foreach ($change in $changeCollection){ + $change | Add-Member SiteCollection($Url) + $change | Add-Member ItemName("N/A") + $change | Add-Member ListName("N/A") + $change | Add-Member WebName("N/A") + $change | Add-Member UserName("N/A") + $change | Add-Member UserTitle("N/A") + + if(! $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("N/A")} + else{ + $leeafyname=$ctx.Web.Lists.GetById($change.ListId).GetItemById($change.ItemId) + $ctx.Load($leeafyname) + $ctx.ExecuteQuery() + $change.ItemName=$leeafyname.LeafName + } + + if(! $change.IsPropertyAvailable("ListId")) { $change | Add-Member ListId("N/A")} + else{ + $listka=$ctx.Web.Lists.GetById($change.ListId) + $ctx.Load($listka) + $ctx.ExecuteQuery() + $change.ListName=$listka.Title + } + + if(! $change.IsPropertyAvailable("WebId")) { $change | Add-Member WebId("N/A")} + else { $change.WebName=$ctx.Web.Url} + + if(! $change.IsPropertyAvailable("UserId")) { $change | Add-Member UserId("N/A")} + else { $ctx.Load($ctx.Web.GetUserById($change.UserId)) + $ctx.ExecuteQuery() + $change.UserName=$ctx.Web.GetUserById($change.UserId).LoginName + $change.UserTitle=$ctx.Web.GetUserById($change.UserId).Title + } + + if(! $change.IsPropertyAvailable("AlertId")) { $change | Add-Member AlertId("N/A")} + + if(! $change.IsPropertyAvailable("Activate")) { $change | Add-Member Activate("N/A")} + + $change | export-csv $CSVPath -Append + } } @@ -96,11 +97,8 @@ $CSVPath="C:\users\ivo\Desktop\changecollectiontry3.csv" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -CSVPath $CSVPath - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -CSVPath $CSVPath } diff --git a/Site Management/ChangeLog/Create a report on all changes for all your site collections/description.md b/Site Management/ChangeLog/Create a report on all changes for all your site collections/description.md index a86e8b4c..55b9fd62 100644 --- a/Site Management/ChangeLog/Create a report on all changes for all your site collections/description.md +++ b/Site Management/ChangeLog/Create a report on all changes for all your site collections/description.md @@ -1,19 +1,25 @@ -Description +### *Description* + The script goes through all SharePoint Online site collections and retrieves a change log for them. The change log is DECRYPTED and published to an Excel file. + What do I mean by decrypted? + Whenever possible and applicable: - User Id is read and dispalyed as SharePoint Online user' LoginName - Document id is read and displayed as Document Name (e.g. title of the Word document) - List id is read and displayed as List Name - Each change is preceded by the name of the site on which it occurred + Whenever the element was not applicable for the particular change "N/A" will be displayed, e.g. When a user deleted a document, alert ID will display N/A because there was no alert created at this activity. When a system sent an alert, user ID and LoginName will display "N/A", because no user was involved. The script is very time-consuming. It needs time to retrieve all logs. For faster script retrieving change logs from only one site collection please consult my other contributions. -Instructions -1. Install SharePoint Online SDK. -2. Before running the script, open the file in Powershell or NotePad and edit the lines below: + +### *Instructions* + +**1.** Install SharePoint Online SDK. +**2.** Before running the script, open the file in Powershell or NotePad and edit the lines below: ```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" @@ -26,14 +32,22 @@ $AdminUrl="https://tenant-admin.sharepoint.com" $CSVPath="C:\users\ivo\Desktop\changecollectiontry3.csv" ``` a) verify where Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll libraries are located on your computer and enter the correct paths. + b) instead of 2190@tenant.onmicrosoft.com enter the name of your administrator + c) instead of https://tenant-admin.sharepoint.com, enter the url for your SharePoint Online admin Center + d) instead of "c:\users\...." enter the path where you want the file to be generated on your local PC -3. Run the script. -4. During the execution you may receive the error "Such list does no longer exist". It is because some of the changes refer to deleted items/lists. -5. When the script is ready, open the created file. The results should be similar to: +**3.** Run the script. +**4.** During the execution you may receive the error "Such list does no longer exist". It is because some of the changes refer to deleted items/lists. + + + +**5.** When the script is ready, open the created file. The results should be similar to: + + -Please share your comments in the Q&A section! -Related scripts -Create a report on all changes for your site collection (Powershell) +### Please share your comments in the Q&A section! +### Related scripts +[Create a report on all changes for your site collection (Powershell)](https://gallery.technet.microsoft.com/Create-a-report-on-all-fe377c62) diff --git a/Site Management/ChangeLog/Create a report on all changes for one site collection/changecollection.ps1 b/Site Management/ChangeLog/Create a report on all changes for one site collection/changecollection.ps1 index 34068753..59155cd2 100644 --- a/Site Management/ChangeLog/Create a report on all changes for one site collection/changecollection.ps1 +++ b/Site Management/ChangeLog/Create a report on all changes for one site collection/changecollection.ps1 @@ -1,79 +1,80 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$CSVPath - - -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ -$ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) -$changeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery $true,$true - -$changeCollection = $ctx.Site.GetChanges($changeQuery) -$ctx.Load($changeCollection) -try -{ -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url " loaded changes" -} catch [Net.WebException] - { - - Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red - -} - -foreach ($change in $changeCollection) -{ -$change | Add-Member SiteCollection($Url) -$change | Add-Member ItemName("N/A") -$change | Add-Member ListName("N/A") -$change | Add-Member WebName("N/A") -$change | Add-Member UserName("N/A") -$change | Add-Member UserTitle("N/A") - -if(! $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("N/A")} else { -$leeafyname=$ctx.Web.Lists.GetById($change.ListId).GetItemById($change.ItemId) -$ctx.Load($leeafyname) -$ctx.ExecuteQuery() -$change.ItemName=$leeafyname.LeafName} -if(! $change.IsPropertyAvailable("ListId")) { $change | Add-Member ListId("N/A")}else { -$listka=$ctx.Web.Lists.GetById($change.ListId) -$ctx.Load($listka) -$ctx.ExecuteQuery() -$change.ListName=$listka.Title} -if(! $change.IsPropertyAvailable("WebId")) { $change | Add-Member WebId("N/A")}else { $change.WebName=$ctx.Web.Url} -if(! $change.IsPropertyAvailable("UserId")) { $change | Add-Member UserId("N/A")}else { $ctx.Load($ctx.Web.GetUserById($change.UserId)) -$ctx.ExecuteQuery() -$change.UserName=$ctx.Web.GetUserById($change.UserId).LoginName -$change.UserTitle=$ctx.Web.GetUserById($change.UserId).Title} -if(! $change.IsPropertyAvailable("AlertId")) { $change | Add-Member AlertId("N/A")} -if(! $change.IsPropertyAvailable("Activate")) { $change | Add-Member Activate("N/A")} - -$change | export-csv $CSVPath -Append -} - - - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $changeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery $true,$true + + $changeCollection = $ctx.Site.GetChanges($changeQuery) + $ctx.Load($changeCollection) + + try{ + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url " loaded changes" + } + catch [Net.WebException] { + Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red + } + + foreach ($change in $changeCollection){ + $change | Add-Member SiteCollection($Url) + $change | Add-Member ItemName("N/A") + $change | Add-Member ListName("N/A") + $change | Add-Member WebName("N/A") + $change | Add-Member UserName("N/A") + $change | Add-Member UserTitle("N/A") + + if(! $change.IsPropertyAvailable("ItemId")) { $change | Add-Member ItemId("N/A")} + else { + $leeafyname=$ctx.Web.Lists.GetById($change.ListId).GetItemById($change.ItemId) + $ctx.Load($leeafyname) + $ctx.ExecuteQuery() + $change.ItemName=$leeafyname.LeafName + } + + if(! $change.IsPropertyAvailable("ListId")) { $change | Add-Member ListId("N/A")} + else { + $listka=$ctx.Web.Lists.GetById($change.ListId) + $ctx.Load($listka) + $ctx.ExecuteQuery() + $change.ListName=$listka.Title + } + + if(! $change.IsPropertyAvailable("WebId")) { $change | Add-Member WebId("N/A")} + else { $change.WebName=$ctx.Web.Url} + + if(! $change.IsPropertyAvailable("UserId")) { $change | Add-Member UserId("N/A")} + else { $ctx.Load($ctx.Web.GetUserById($change.UserId)) + $ctx.ExecuteQuery() + $change.UserName=$ctx.Web.GetUserById($change.UserId).LoginName + $change.UserTitle=$ctx.Web.GetUserById($change.UserId).Title + } + + if(! $change.IsPropertyAvailable("AlertId")) { $change | Add-Member AlertId("N/A")} + + if(! $change.IsPropertyAvailable("Activate")) { $change | Add-Member Activate("N/A")} + + $change | export-csv $CSVPath -Append + } } @@ -96,11 +97,8 @@ $CSVPath="C:\users\ivo\Desktop\changecollectiontry3.csv" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -CSVPath $CSVPath - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -CSVPath $CSVPath } diff --git a/Site Management/ChangeLog/Create a report on all changes for one site collection/description.md b/Site Management/ChangeLog/Create a report on all changes for one site collection/description.md index 20429fce..263db4cf 100644 --- a/Site Management/ChangeLog/Create a report on all changes for one site collection/description.md +++ b/Site Management/ChangeLog/Create a report on all changes for one site collection/description.md @@ -1,19 +1,22 @@ -

Description

+### *Description* The script retrieves a change log for a specified site collection. The change log is DECRYPTED and published to an Excel file: + Whenever possible and applicable: - User Id is read and dispalyed as SharePoint Online user' LoginName - Document id is read and displayed as Document Name (e.g. title of the Word document) - List id is read and displayed as List Name - Each change is preceded by the name of the site on which it occurred + Whenever the element was not applicable for the particular change "N/A" will be displayed, e.g. When a user deleted a document, alert ID will display N/A because there was no alert created at this activity. When a system sent an alert, user ID and LoginName will display "N/A", because no user was involved. -Instructions +### *Instructions* + +**1.** Install SharePoint Online SDK. -1. Install SharePoint Online SDK. -2. Before running the script, open the file in Powershell or NotePad and edit the lines below: +**2.** Before running the script, open the file in Powershell or NotePad and edit the lines below: ```Powershell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" @@ -26,15 +29,25 @@ $AdminUrl="https://tenant-admin.sharepoint.com" $CSVPath="C:\users\ivo\Desktop\changecollectiontry3.csv" ``` a) verify where Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll libraries are located on your computer and enter the correct paths. + b) instead of 2190@tenant.onmicrosoft.com enter the name of your administrator + c) instead of https://tenant-admin.sharepoint.com, enter the url for your SharePoint Online admin Center + d) instead of "c:\users\...." enter the path where you want the file to be generated on your local PC -3. Run the script. -4. During the execution you may receive the error "Such list does no longer exist". It is because some of the changes refer to deleted items/lists. -5. When the script is ready, open the created file. The results should be similar to: +**3.** Run the script. + +**4.** During the execution you may receive the error "Such list does no longer exist". It is because some of the changes refer to deleted items/lists. + + + + + +**5.** When the script is ready, open the created file. The results should be similar to: + +### Please share your comments in the Q&A section! -Please share your comments in the Q&A section! +**Related scripts:** -Related scripts: -Create a report on all changes for all your site collections +[Create a report on all changes for all your site collections](https://gallery.technet.microsoft.com/Create-a-report-on-all-2a4e7409) diff --git a/Site Management/Create OneDrive for Business usage report for all users/description.md b/Site Management/Create OneDrive for Business usage report for all users/description.md deleted file mode 100644 index 92be00d5..00000000 --- a/Site Management/Create OneDrive for Business usage report for all users/description.md +++ /dev/null @@ -1,45 +0,0 @@ -The script retrieves all SPO users and pulls usage statistics for their ODB sites. - - - -The script uses CSOM. It requires SharePoint Online SDK and SharePoint Online Management Shell. Make sure the script refers the paths on your computer: - - - -PowerShell -# Paths to SDK. Please verify location on your computer. -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - - - -How to use? -1. Download the script and open it in ISE or NotePad. - -2. Enter your tenant's data: - - - -PowerShell -$admin="user@tenant.onmicrosoft.com" -$pass=Read-Host "Enter Password: " -AsSecureString -$mysiteHost="https://tenant-my.sharepoint.com" - - - -3. Run the script. - -4. Expected results: - - - - - - - - - -Acknowledgement: -The script is using Invoke-LoadMethod published here, without which it could not proceed. The method was created and belongs to a brilliant SharePointer and Guru, Vadim Gremyachev. diff --git a/Site Management/Enable page editing when master page editing has been disabled for this site/AllowMasterPageEditing.ps1 b/Site Management/Enable page editing when master page editing has been disabled for this site/AllowMasterPageEditing.ps1 index ccccf1d6..8005c3ac 100644 --- a/Site Management/Enable page editing when master page editing has been disabled for this site/AllowMasterPageEditing.ps1 +++ b/Site Management/Enable page editing when master page editing has been disabled for this site/AllowMasterPageEditing.ps1 @@ -1,46 +1,39 @@ -function Set-SPOSiteAllowMasterPageEditing -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOSiteAllowMasterPageEditing{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, -[Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [bool]$setting - -) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ -$ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) - $ctx.Load($ctx.Web.Webs) - $ctx.Site.AllowMasterPageEditing=$setting - - - try - { - $ctx.ExecuteQuery() - $ctx.Load($ctx.Site) - $ctx.ExecuteQuery() - Write-Host "Success. AllowMasterPageEditing is now set to " $ctx.Site.AllowMasterPageEditing -ForegroundColor Green - } - catch [Net.WebException] - { - Write-Host "Failed to set the setting" $_.Exception.Message.ToString() -ForegroundColor Red - } - + ) + + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $ctx.Load($ctx.Web.Webs) + $ctx.Site.AllowMasterPageEditing=$setting + + + try{ + $ctx.ExecuteQuery() + $ctx.Load($ctx.Site) + $ctx.ExecuteQuery() + Write-Host "Success. AllowMasterPageEditing is now set to " $ctx.Site.AllowMasterPageEditing -ForegroundColor Green + } + catch [Net.WebException] { + Write-Host "Failed to set the setting" $_.Exception.Message.ToString() -ForegroundColor Red + } } @@ -55,4 +48,4 @@ $Url="https://tenant.sharepoint.com/sites/teamsitewithlibraries" $setting=$true -Set-SPOSiteAllowMasterPageEditing -Username $Username -AdminPassword $AdminPassword -Url $Url -setting $setting \ No newline at end of file +Set-SPOSiteAllowMasterPageEditing -Username $Username -AdminPassword $AdminPassword -Url $Url -setting $setting diff --git a/Site Management/Enable page editing when master page editing has been disabled for this site/description.md b/Site Management/Enable page editing when master page editing has been disabled for this site/description.md index b72f8e1a..15666011 100644 --- a/Site Management/Enable page editing when master page editing has been disabled for this site/description.md +++ b/Site Management/Enable page editing when master page editing has been disabled for this site/description.md @@ -2,19 +2,19 @@ When you receive the error "Master page editing has been disabled for this site. -How to use? +## How to use? -1. Download and install SharePoint Online SDK. +**1.** Download and install [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038). -2. Download the .ps1 file. +**2.** Download the ```.ps1``` file. -3. Open the file (you can do it also in NotePad) +**3.** Open the file (you can do it also in NotePad) -4. Insert your data in these lines: +**4.** Insert your data in these lines: -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -24,27 +24,18 @@ $Username="admin@tenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $Url="https://tenant.sharepoint.com/sites/teamsitewithlibraries" $setting=$true +``` a) Find on your computer where SharePoint.Clitent.dll and SharePoint.Client.Runtime.dll libraries are located and insert the correct paths -b) Instead of "admin@tenant.onmicrosoft.com" enter you username -c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to change the setting -d) If you want to ENABLE master page editing, skip the next line. If you want to DISABLE master page editing, change it to $false -5. Run the script in Powershell (any module). -6. At the end you should receive a confirmation message like this: - - - - - - - +b) Instead of "admin@tenant.onmicrosoft.com" enter you username - +c) Instead of "https://tenant.sharepoint.com/sites/teamsitewithlibraries" enter the name of the site collection where you want to change the setting - +d) If you want to ENABLE master page editing, skip the next line. If you want to DISABLE master page editing, change it to $false - +**5.** Run the script in Powershell (any module). +**6.** At the end you should receive a confirmation message like this: - + Please share your feedback in the Q&A section diff --git a/Site Management/Export site collection properties using Powershell and CSOM/SiteCollPropertiesWithCSOM.ps1 b/Site Management/Export site collection properties using Powershell and CSOM/SiteCollPropertiesWithCSOM.ps1 index 54860404..a1fd510d 100644 --- a/Site Management/Export site collection properties using Powershell and CSOM/SiteCollPropertiesWithCSOM.ps1 +++ b/Site Management/Export site collection properties using Powershell and CSOM/SiteCollPropertiesWithCSOM.ps1 @@ -1,30 +1,27 @@ -function Get-SiteColl -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SiteColl{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] $password - ) + ) - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() - $spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx) - $spoTenantSiteCollections=$spoTenant.GetSiteProperties(0,$true) - $ctx.Load($spoTenantSiteCollections) - $ctx.ExecuteQuery() - - foreach($siteColl in $spoTenantSiteCollections) - { - Write-Output $siteColl - } + $spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx) + $spoTenantSiteCollections=$spoTenant.GetSiteProperties(0,$true) + $ctx.Load($spoTenantSiteCollections) + $ctx.ExecuteQuery() + foreach($siteColl in $spoTenantSiteCollections){ + Write-Output $siteColl + } } @@ -44,4 +41,4 @@ $Url="https://TENANT-admin.sharepoint.com" -Get-SiteColl -Username $username -Url $Url -password $AdminPassword | Export-Csv C:\Users\Arleta.Wanat\Desktop\'August 2017'\testcsv.csv \ No newline at end of file +Get-SiteColl -Username $username -Url $Url -password $AdminPassword | Export-Csv C:\Users\Arleta.Wanat\Desktop\'August 2017'\testcsv.csv diff --git a/Site Management/Export site collection properties using Powershell and CSOM/description.md b/Site Management/Export site collection properties using Powershell and CSOM/description.md index 5f16ad1c..c02155b7 100644 --- a/Site Management/Export site collection properties using Powershell and CSOM/description.md +++ b/Site Management/Export site collection properties using Powershell and CSOM/description.md @@ -2,25 +2,14 @@ Short Powershell script to export properties of all site collections. Sample properties include AllowSelfServiceUpgrade, FalseAverageResourceUsage, CompatibilityLevel, CurrentResourceUsage, DenyAddAndCustomizePages, DisableAppViews, DisableCompanyWideSharingLinks, DisableFlows, PWAEnabled, SandboxedCodeActivationCapability, SharingAllowedDomainList, ShowPeoplePickerSuggestionsForGuestUsers, SiteDefinedSharingCapability - - - - - - Expected results: - - - - - - - + ### How to use? -Download and open the .ps1 file. -Add correct libraries: + +- Download and open the ```.ps1``` file. +- Add correct libraries: ```PowerShell @@ -28,7 +17,7 @@ Add correct libraries: Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll" ``` -Enter the correct url and admin login: +- Enter the correct url and admin login: ```PowerShell @@ -37,4 +26,4 @@ $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="admin@TENANT.onmicrosoft.com" $Url="https://TENANT-admin.sharepoint.com" ``` - Run the script +- Run the script diff --git a/Site Management/Features/Activate or deactivate a SPO feature for a single site/description.md b/Site Management/Features/Activate or deactivate a SPO feature for a single site/description.md index b1bf9fe4..3063fca7 100644 --- a/Site Management/Features/Activate or deactivate a SPO feature for a single site/description.md +++ b/Site Management/Features/Activate or deactivate a SPO feature for a single site/description.md @@ -1,39 +1,28 @@ -A simple script for SharePoint Online that enables a feature in a single SPO site (site collection or a subsite). You need to have the required permissions for the site and known the feature guid. The list of guids can be found here: -http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx - - +A simple script for SharePoint Online that enables a feature in a single SPO site (site collection or a subsite). You need to have the required permissions for the site and known the feature guid. The list of guids can be found [here](http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx). Before running the script, verify the paths to SharePoint Online SDK: - - -PowerShell +```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" + ``` - - Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - -PowerShell +```PowerShell $siteUrl = Read-Host -Prompt "Enter https://tenant.sharepoint.com/sites/mysitecollection” $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" - + ``` During its execution the script will inform you, where the features have been changed. +### Related scripts: - - -Related scripts: - -Activate or deactivate a feature for a site and its subsites +[Activate or deactivate a feature for a site and its subsites](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-bc6534e9) -Activate or deactivate a SPO feature for direct subsites in site collection +[Activate or deactivate a SPO feature for direct subsites in site collection](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-9fe2fb34) diff --git a/Site Management/Features/Activate or deactivate a SPO feature for a single site/enablefeatureForASingleSite.ps1 b/Site Management/Features/Activate or deactivate a SPO feature for a single site/enablefeatureForASingleSite.ps1 index 917a2ec5..b47594c8 100644 --- a/Site Management/Features/Activate or deactivate a SPO feature for a single site/enablefeatureForASingleSite.ps1 +++ b/Site Management/Features/Activate or deactivate a SPO feature for a single site/enablefeatureForASingleSite.ps1 @@ -1,54 +1,46 @@ -function Remove-SPOFeature -{ -param ( - [string]$Username, +function Remove-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) - -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Web -$ctx.Load($site) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() - - - $site.Features.Remove($featureguid, $true); - $ctx.ExecuteQuery() - Write-Host "Feature removed for" $site.Url + ) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $site=$ctx.Web + $ctx.Load($site) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + $site.Features.Remove($featureguid, $true); + $ctx.ExecuteQuery() + Write-Host "Feature removed for" $site.Url } -function Add-SPOFeature -{ -param ( - [string]$Username, +function Add-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) + ) -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Web -$ctx.Load($site) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $site=$ctx.Web + $ctx.Load($site) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() - $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) - $ctx.ExecuteQuery() - Write-Host "Feature enabled for" $site.Url - + $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) + $ctx.ExecuteQuery() + Write-Host "Feature enabled for" $site.Url } @@ -62,35 +54,27 @@ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -try -{ -$ctx.ExecuteQuery() +try{ + $ctx.ExecuteQuery() +} +catch [Net.WebException] { + Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red } -catch [Net.WebException] - { - - Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red - } $feature=Read-Host -Prompt "Enter the feature id, e.g. for SharePoint Server Publishing it's 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" $featureguid=new-object System.Guid $feature $RemoveorAdd= Read-Host "Do you want to activate the feature to the sites (a) or deactivate it (d)? Press a or d." $RemoveorAdd=$RemoveorAdd.Trim() -if($RemoveorAdd -like "a") -{ - - Add-SPOFeature -Username $username -Url $siteUrl -password $password - +if($RemoveorAdd -like "a"){ + Add-SPOFeature -Username $username -Url $siteUrl -password $password + } -elseif($RemoveorAdd -like "d") -{ - Remove-SPOFeature -Username $username -Url $siteUrl -password $password - +elseif($RemoveorAdd -like "d"){ + Remove-SPOFeature -Username $username -Url $siteUrl -password $password } -else -{ -Write-Host "Didn't recognize the command" +else{ + Write-Host "Didn't recognize the command" } diff --git a/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/description.md b/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/description.md index ebce20e5..2643c966 100644 --- a/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/description.md +++ b/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/description.md @@ -1,8 +1,8 @@ -A simple script for SharePoint Online that finds all direct (one-level down) subsites in a provided site collection and enables the chosen SharePoint feature for all of them. You need to have the required permissions for the site and known the feature guid. The list of guids can be found here: -http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx +A simple script for SharePoint Online that finds all direct (one-level down) subsites in a provided site collection and enables the chosen SharePoint feature for all of them. You need to have the required permissions for the site and known the feature guid. The list of guids can be found [here](http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx). -##### Related scripts +#### Related scripts + Activate or deactivate a feature for a site and its subsites [GitHub](https://github.com/PowershellScripts/AllGalleryScriptsSamples/tree/master/Site%20Management/Features/Activate%20or%20deactivate%20a%20feature%20for%20a%20site%20and%20its%20subsites) [Technet Gallery](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-bc6534e9) Activate or deactivate a SPO feature for a single site [GitHub](https://github.com/PowershellScripts/AllGalleryScriptsSamples/tree/master/Site%20Management/Features/Activate%20or%20deactivate%20a%20SPO%20feature%20for%20a%20single%20site) [Technet Gallery](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-da769f9d) diff --git a/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/enablefeature.ps1 b/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/enablefeature.ps1 index f5b894eb..98c7e303 100644 --- a/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/enablefeature.ps1 +++ b/Site Management/Features/Activate or deactivate a SPO feature for direct subsites in site collection/enablefeature.ps1 @@ -19,32 +19,25 @@ $featureguid=new-object System.Guid $feature $RemoveorAdd= Read-Host "Do you want to activate the feature to the sites (a) or deactivate it (d)? Press a or d." $RemoveorAdd=$RemoveorAdd.Trim() -if($RemoveorAdd -like "a") -{ - - foreach($site in $sites) - { - $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) - #$site.Features.Remove($featureguid, $true); - $ctx.ExecuteQuery() - Write-Host "Feature enabled for" $site.Url +if($RemoveorAdd -like "a"){ + foreach($site in $sites){ + $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) + #$site.Features.Remove($featureguid, $true); + $ctx.ExecuteQuery() + Write-Host "Feature enabled for" $site.Url } Write-Host "Done." } -elseif($RemoveorAdd -like "d") -{ - - foreach($site in $sites) - { - $site.Features.Remove($featureguid, $true); - $ctx.ExecuteQuery() - Write-Host "Feature removed for" $site.Url +elseif($RemoveorAdd -like "d"){ + foreach($site in $sites){ + $site.Features.Remove($featureguid, $true); + $ctx.ExecuteQuery() + Write-Host "Feature removed for" $site.Url } Write-Host "Done." } -else -{ -Write-Host "Didn't recognize the command" +else{ + Write-Host "Didn't recognize the command" } diff --git a/Site Management/Features/Activate or deactivate a feature for a site and its subsites/description.md b/Site Management/Features/Activate or deactivate a feature for a site and its subsites/description.md index 66f37737..156210ed 100644 --- a/Site Management/Features/Activate or deactivate a feature for a site and its subsites/description.md +++ b/Site Management/Features/Activate or deactivate a feature for a site and its subsites/description.md @@ -1,29 +1,18 @@ -A simple script for SharePoint Online that activates or de-activates a feature for a site,then finds all its subsites and enables/disables the chosen SharePoint feature for all of them. You need to have the required permissions for the site and known the feature guid. The list of guids can be found here: +A simple script for SharePoint Online that activates or de-activates a feature for a site,then finds all its subsites and enables/disables the chosen SharePoint feature for all of them. You need to have the required permissions for the site and known the feature guid. The list of guids can be found [here](http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx). -http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx +Before running the script, verify the paths to [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038): - - - - -Before running the script, verify the paths to SharePoint Online SDK: - - - -PowerShell +```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - + ``` Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - -PowerShell +```PowerShell $siteUrl = Read-Host -Prompt "Enter https://tenant.sharepoint.com/sites/mysitecollection” $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" - + ``` During its execution the script will inform you, where the features have been changed. @@ -36,9 +25,8 @@ During its execution the script will inform you, where the features have been ch -Related scripts - +### Related scripts -Activate or deactivate a SPO feature for direct subsites in site collection +[Activate or deactivate a SPO feature for direct subsites in site collection](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-bc6534e9) -Activate or deactivate a SPO feature for a single site +[Activate or deactivate a SPO feature for a single site](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-9fe2fb34) diff --git a/Site Management/Features/Activate or deactivate a feature for a site and its subsites/enablefeatureWithRecursion.ps1 b/Site Management/Features/Activate or deactivate a feature for a site and its subsites/enablefeatureWithRecursion.ps1 index a66670b4..e8d46666 100644 --- a/Site Management/Features/Activate or deactivate a feature for a site and its subsites/enablefeatureWithRecursion.ps1 +++ b/Site Management/Features/Activate or deactivate a feature for a site and its subsites/enablefeatureWithRecursion.ps1 @@ -1,68 +1,60 @@ -function Remove-SPOFeature -{ -param ( - [string]$Username, +function Remove-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) + ) -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Web -$ctx.Load($site) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $site=$ctx.Web + $ctx.Load($site) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() - $site.Features.Remove($featureguid, $true); - $ctx.ExecuteQuery() - Write-Host "Feature removed for" $site.Url - if($ctx.Web.Webs.Count -gt 0) - { - foreach ($web in $ctx.Web.Webs) - { - Remove-SPOFeature -Username $Username -Url $web.Url -password $password - } - } + $site.Features.Remove($featureguid, $true); + $ctx.ExecuteQuery() + Write-Host "Feature removed for" $site.Url + if($ctx.Web.Webs.Count -gt 0){ + foreach ($web in $ctx.Web.Webs){ + Remove-SPOFeature -Username $Username -Url $web.Url -password $password + } + } } -function Add-SPOFeature -{ -param ( - [string]$Username, +function Add-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) + ) -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Web -$ctx.Load($site) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() - - - $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) - $ctx.ExecuteQuery() - Write-Host "Feature enabled for" $site.Url - - if($ctx.Web.Webs.Count -gt 0) - { - foreach ($web in $ctx.Web.Webs) - { - Add-SPOFeature -Username $Username -Url $web.Url -password $password - } - } - + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + + $site=$ctx.Web + $ctx.Load($site) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + + + $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) + $ctx.ExecuteQuery() + Write-Host "Feature enabled for" $site.Url + + if($ctx.Web.Webs.Count -gt 0){ + foreach ($web in $ctx.Web.Webs){ + Add-SPOFeature -Username $Username -Url $web.Url -password $password + } + } } @@ -76,35 +68,26 @@ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -try -{ -$ctx.ExecuteQuery() +try{ + $ctx.ExecuteQuery() +} +catch [Net.WebException] { + Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red } -catch [Net.WebException] - { - - Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red - } $feature=Read-Host -Prompt "Enter the feature id, e.g. for SharePoint Server Publishing it's 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" $featureguid=new-object System.Guid $feature $RemoveorAdd= Read-Host "Do you want to activate the feature to the sites (a) or deactivate it (d)? Press a or d." $RemoveorAdd=$RemoveorAdd.Trim() -if($RemoveorAdd -like "a") -{ - - Add-SPOFeature -Username $username -Url $siteUrl -password $password - +if($RemoveorAdd -like "a"){ + Add-SPOFeature -Username $username -Url $siteUrl -password $password } -elseif($RemoveorAdd -like "d") -{ - Remove-SPOFeature -Username $username -Url $siteUrl -password $password - +elseif($RemoveorAdd -like "d"){ + Remove-SPOFeature -Username $username -Url $siteUrl -password $password } -else -{ -Write-Host "Didn't recognize the command" +else{ + Write-Host "Didn't recognize the command" } diff --git a/Site Management/Features/Activate or deactivate a site collection feature/description.md b/Site Management/Features/Activate or deactivate a site collection feature/description.md index 01661ede..371183e3 100644 --- a/Site Management/Features/Activate or deactivate a site collection feature/description.md +++ b/Site Management/Features/Activate or deactivate a site collection feature/description.md @@ -1,37 +1,28 @@ -A simple script for SharePoint Online that activates or de-activates a feature for a site collection. You need to have the required permissions for the site collection and know the feature guid. The list of guids can be found here: +A simple script for SharePoint Online that activates or de-activates a feature for a site collection. You need to have the required permissions for the site collection and know the feature guid. The list of guids can be found [here]( +http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx). -http://blogs.msdn.com/b/razi/archive/2013/10/28/listing-all-sharepoint-2013-features-including-name-title-scope-id-and-description.aspx - - - - - -Before running the script, verify the paths to SharePoint Online SDK: - - +Before running the script, verify the paths to [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038): ```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" ``` - Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - ```PowerShell $siteUrl = Read-Host -Prompt "Enter https://tenant.sharepoint.com/sites/mysitecollection” $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" ``` - During its execution the script will inform you, when the feature has been changed. -##### Related scripts +### Related scripts + +[Activate or deactivate a SPO feature for direct subsites in site collection](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-9fe2fb34) -Activate or deactivate a SPO feature for direct subsites in site collection [GitHub]( [Technet Gallery] +[Activate or deactivate a SPO feature for a single site](https://github.com/PowershellScripts/AllGalleryScriptsSamples/tree/master/Site%20Management/Features/Activate%20or%20deactivate%20a%20SPO%20feature%20for%20a%20single%20site) -Activate or deactivate a SPO feature for a single site [GitHub](https://github.com/PowershellScripts/AllGalleryScriptsSamples/tree/master/Site%20Management/Features/Activate%20or%20deactivate%20a%20SPO%20feature%20for%20a%20single%20site) [TechnetGallery](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-da769f9d) +[TechnetGallery](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-da769f9d) diff --git a/Site Management/Features/Add/Remove Site Features from all Personal Sites/AddFeaturesToPersonal.ps1 b/Site Management/Features/Add/Remove Site Features from all Personal Sites/AddFeaturesToPersonal.ps1 deleted file mode 100644 index 881acd45..00000000 --- a/Site Management/Features/Add/Remove Site Features from all Personal Sites/AddFeaturesToPersonal.ps1 +++ /dev/null @@ -1,125 +0,0 @@ -function Remove-SPOFeature -{ -param ( - [string]$Username, - [Parameter(Mandatory=$true,Position=1)] - [string]$Url, - [Parameter(Mandatory=$true,Position=2)] - $password -) - -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Site -$ctx.Load($site) -$ctx.ExecuteQuery() - - - $site.Features.Remove($featureguid, $true); - $ctx.ExecuteQuery() - Write-Host "Feature removed for" $site.Url - - - -} - - -function Add-SPOFeature -{ -param ( - [string]$Username, - [Parameter(Mandatory=$true,Position=1)] - [string]$Url, - [Parameter(Mandatory=$true,Position=2)] - $password -) - -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Site -$ctx.Load($site) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() - - - $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) - $ctx.ExecuteQuery() - Write-Host "Feature enabled for" $site.Url - - - -} - - - - -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" -$csvPath= Read-Host -Prompt "Enter the path of the csv file" -$users=import-csv $csvPath -$siteUrl = Read-Host -Prompt "Enter the my site host: https://tenant-my.sharepoint.com” -$username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" -$password = Read-Host -Prompt "Enter password" -AsSecureString -$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) -$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -$ctx.Credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -$adminUrl=$siteUrl.Replace("-my","-admin") -Connect-SPOService -Url $adminUrl -Credential $username - -try -{ -$ctx.ExecuteQuery() -} -catch [Net.WebException] - { - - Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red - } - -$feature=Read-Host -Prompt "Enter the feature id, e.g. for SharePoint Server Publishing it's 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" -$featureguid=new-object System.Guid $feature -$RemoveorAdd= Read-Host "Do you want to activate the feature to the sites (a) or deactivate it (d)? Press a or d." -$RemoveorAdd=$RemoveorAdd.Trim() - -if($RemoveorAdd -like "a") -{ - - foreach($user in $users) - { - if($user.Site -ne "") - { - $urelek=$siteUrl+$user.Site - $urelek=$urelek.TrimEnd("/") - Set-SPOUser -Site $urelek -LoginName $username -IsSiteCollectionAdmin $true - Add-SPOFeature -Username $username -Url $urelek -password $password - - #Set-SPOUser -Site $urelek -LoginName $username -IsSiteCollectionAdmin $false - - } - -} -} -elseif($RemoveorAdd -like "d") -{ - foreach($user in $users) - { - if($user.Site -ne "") - { - $urelek=$siteUrl+$user.Site - $urelek=$urelek.TrimEnd("/") - Set-SPOUser -Site $urelek -LoginName $username -IsSiteCollectionAdmin $true - Remove-SPOFeature -Username $username -Url $urelek -password $password - } - } -} -else -{ -Write-Host "Didn't recognize the command" -} - - - -Write-Host "Done." -ForegroundColor Green - diff --git a/Site Management/Features/Add/Remove Site Features from all Personal Sites/description.md b/Site Management/Features/Add/Remove Site Features from all Personal Sites/description.md deleted file mode 100644 index f2c1fa5a..00000000 --- a/Site Management/Features/Add/Remove Site Features from all Personal Sites/description.md +++ /dev/null @@ -1,60 +0,0 @@ -This script is a temporary solution intended to work together with Retrieve all SharePoint Online profiles and their properties using CSOM. - -Using Retrieve all SharePoint Online profiles and their properties using CSOM generate a CSV file with personal sites in the format: - - - -Site -/personal/t_trial234_onmicrosoft_com/ -/personal/uss100_trial234_onmicrosoft_com/ -/personal/t_trial234_onmicrosoft_com/ - - -The Column name has to be SITE. - - - -Run the script. It will ask you for credentials, feature id, and whether you want to acivate it or de-activate. - - - -Before running the script, verify the paths to SharePoint Online SDK: - - - -PowerShell -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" -Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - -Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - - -During its execution the script will inform you, where the features have been changed. - - - - - - - - - -Related scripts - - -Activate or deactivate a SPO feature for direct subsites in site collection - -Activate or deactivate a SPO feature for a single site - -Activate or deactivate a site collection feature - -Get all features from a site collection - -Get all features from a site - - - -** As a side-effect the script assigns the administrator as a site collection admin to all users. This will be improved in the next version** diff --git a/Site Management/Features/Enable feature/enablefeature.ps1 b/Site Management/Features/Enable feature/enablefeature.ps1 index 2c8c5acb..a68f2567 100644 --- a/Site Management/Features/Enable feature/enablefeature.ps1 +++ b/Site Management/Features/Enable feature/enablefeature.ps1 @@ -24,32 +24,25 @@ $featureguid=new-object System.Guid $feature $RemoveorAdd= Read-Host "Do you want to activate the feature to the sites (a) or deactivate it (d)? Press a or d." $RemoveorAdd=$RemoveorAdd.Trim() -if($RemoveorAdd -like "a") -{ - - foreach($site in $sites) - { +if($RemoveorAdd -like "a"){ + foreach($site in $sites){ $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) #$site.Features.Remove($featureguid, $true); $ctx.ExecuteQuery() Write-Host "Feature enabled for" $site.Url - } - Write-Host "Done." + } + Write-Host "Done." } -elseif($RemoveorAdd -like "d") -{ - - foreach($site in $sites) - { +elseif($RemoveorAdd -like "d"){ + foreach($site in $sites){ $site.Features.Remove($featureguid, $true); $ctx.ExecuteQuery() Write-Host "Feature removed for" $site.Url - } + } Write-Host "Done." } -else -{ -Write-Host "Didn't recognize the command" +else{ + Write-Host "Didn't recognize the command" } diff --git a/Site Management/Features/Get all features from a site collection/GetSPOSiteFeatures.ps1 b/Site Management/Features/Get all features from a site collection/GetSPOSiteFeatures.ps1 index f00fe564..d29918cd 100644 --- a/Site Management/Features/Get all features from a site collection/GetSPOSiteFeatures.ps1 +++ b/Site Management/Features/Get all features from a site collection/GetSPOSiteFeatures.ps1 @@ -1,29 +1,24 @@ -function Get-SPOFeature -{ -param ( - [string]$Username, +function Get-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) - -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Site -$ctx.Load($site.Features) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() + ) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - for($i=0;$i -lt $site.Features.Count ;$i++) -{ + $site=$ctx.Site + $ctx.Load($site.Features) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() -Write-Output $site.Features[$i].DefinitionID - -} + for($i=0;$i -lt $site.Features.Count ;$i++){ + Write-Output $site.Features[$i].DefinitionID + } } @@ -40,23 +35,14 @@ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -try -{ -$ctx.ExecuteQuery() +try{ + $ctx.ExecuteQuery() +} +catch [Net.WebException] { + Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red } -catch [Net.WebException] - { - - Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red - } - - - - Get-SPOFeature -Username $username -Url $siteUrl -password $password +Get-SPOFeature -Username $username -Url $siteUrl -password $password - - - Write-Host "Done." -ForegroundColor Green diff --git a/Site Management/Features/Get all features from a site collection/description.md b/Site Management/Features/Get all features from a site collection/description.md index 0e684c55..66348e51 100644 --- a/Site Management/Features/Get all features from a site collection/description.md +++ b/Site Management/Features/Get all features from a site collection/description.md @@ -1,23 +1,14 @@ A simple script for SharePoint Online to get all site collection features activated at a particular site collection. - - - - Before running the script, verify the paths to SharePoint Online SDK: - - -PowerShell +```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - + ``` Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - ```PowerShell $siteUrl = Read-Host -Prompt "Enter https://tenant.sharepoint.com/sites/mysitecollection” $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" @@ -26,21 +17,11 @@ $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" During its execution the script will inform you what features are activated in a given site collection: - - - - - - - - - - - + -#### Related scripts +### Related scripts -Activate or deactivate a SPO feature for direct subsites in site collection +[Activate or deactivate a SPO feature for direct subsites in site collection](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-9fe2fb34) -Activate or deactivate a SPO feature for a single site +[Activate or deactivate a SPO feature for a single site](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-da769f9d) diff --git a/Site Management/Features/Get all features from a site/GetSPOWebFeatures.ps1 b/Site Management/Features/Get all features from a site/GetSPOWebFeatures.ps1 index bb47ab43..41ef0ebf 100644 --- a/Site Management/Features/Get all features from a site/GetSPOWebFeatures.ps1 +++ b/Site Management/Features/Get all features from a site/GetSPOWebFeatures.ps1 @@ -1,29 +1,24 @@ -function Get-SPOFeature -{ -param ( - [string]$Username, +function Get-SPOFeature{ + param ( + [string]$Username, [Parameter(Mandatory=$true,Position=1)] [string]$Url, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password -) - -$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - -$site=$ctx.Web -$ctx.Load($site.Features) -$ctx.Load($ctx.Web.Webs) -$ctx.ExecuteQuery() + ) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - for($i=0;$i -lt $site.Features.Count ;$i++) -{ + $site=$ctx.Web + $ctx.Load($site.Features) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() -Write-Output $site.Features[$i].DefinitionID - -} + for($i=0;$i -lt $site.Features.Count ;$i++){ + Write-Output $site.Features[$i].DefinitionID + } } @@ -40,23 +35,14 @@ $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) -try -{ -$ctx.ExecuteQuery() +try{ + $ctx.ExecuteQuery() +} +catch [Net.WebException] { + Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red } -catch [Net.WebException] - { - - Write-Host "Wrong credentials" $_.Exception.Message -ForegroundColor Red - } - - - - - Get-SPOFeature -Username $username -Url $siteUrl -password $password - - +Get-SPOFeature -Username $username -Url $siteUrl -password $password Write-Host "Done." -ForegroundColor Green diff --git a/Site Management/Features/Get all features from a site/description.md b/Site Management/Features/Get all features from a site/description.md index 66b017c3..a73c606d 100644 --- a/Site Management/Features/Get all features from a site/description.md +++ b/Site Management/Features/Get all features from a site/description.md @@ -1,50 +1,25 @@ -A simple script for SharePoint Online to retrieve all site features activated at a site level (not site collection). - - - - - - +A simple script for SharePoint Online to **retrieve all site features activated at a site level** (not site collection). Before running the script, verify the paths to SharePoint Online SDK: - - -PowerShell +```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" + ``` - - Optionally, you can edit these two lines so that the script doesn'task you for credentials at runtime: - - -PowerShell +```PowerShell $siteUrl = Read-Host -Prompt "Enter https://tenant.sharepoint.com/sites/mysitecollection” $username = Read-Host -Prompt "Enter admin@tenant.onmicrosoft.com" - - +``` During its execution the script will inform you what features are activated in a given site collection. - - - - - - - - - - - - -Related scripts - +### Related scripts -Activate or deactivate a SPO feature for direct subsites in site collection +[Activate or deactivate a SPO feature for direct subsites in site collection](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-9fe2fb34) -Activate or deactivate a SPO feature for a single site +[Activate or deactivate a SPO feature for a single site](https://gallery.technet.microsoft.com/office/Activate-or-deactivate-a-da769f9d) -Get all features from a site collection +[Get all features from a site collection](https://gallery.technet.microsoft.com/Get-all-features-from-a-2954b47a) diff --git a/Site Management/Get SharePoint Online Access Requests Settings with REST API/GetSPOAccessRequestsWithREST.ps1 b/Site Management/Get SharePoint Online Access Requests Settings with REST API/GetSPOAccessRequestsWithREST.ps1 index 42be46bf..3c84e30f 100644 --- a/Site Management/Get SharePoint Online Access Requests Settings with REST API/GetSPOAccessRequestsWithREST.ps1 +++ b/Site Management/Get SharePoint Online Access Requests Settings with REST API/GetSPOAccessRequestsWithREST.ps1 @@ -1,54 +1,34 @@ -function Get-AccessRequests -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-AccessRequests{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string] $url - ) + ) - - $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')" - - - - $request = [System.Net.WebRequest]::Create($RESTUrl) - $request.Credentials = $Credentials - $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") - $request.Accept = "application/json;odata=verbose" - [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get - $request.Method=$Method - $response = $request.GetResponse() - $requestStream = $response.GetResponseStream() - $read = New-Object System.IO.StreamReader $requestStream - $data=$read.ReadToEnd() - $results = $data | ConvertFrom-Json - - - - - Write-Output ($results.d) - - - - - - - - - } - + $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')" - - + $request = [System.Net.WebRequest]::Create($RESTUrl) + $request.Credentials = $Credentials + $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") + $request.Accept = "application/json;odata=verbose" + [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get + $request.Method=$Method + $response = $request.GetResponse() + $requestStream = $response.GetResponseStream() + $read = New-Object System.IO.StreamReader $requestStream + $data=$read.ReadToEnd() + $results = $data | ConvertFrom-Json + Write-Output ($results.d) +} #Paths to SDK Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.dll" @@ -63,4 +43,4 @@ $Url="https://t321.sharepoint.com/polski" -Get-AccessRequests -Username $username -Url $Url -password $AdminPassword \ No newline at end of file +Get-AccessRequests -Username $username -Url $Url -password $AdminPassword diff --git a/Site Management/Get SharePoint Online Access Requests Settings with REST API/description.md b/Site Management/Get SharePoint Online Access Requests Settings with REST API/description.md index ff805079..a433e92b 100644 --- a/Site Management/Get SharePoint Online Access Requests Settings with REST API/description.md +++ b/Site Management/Get SharePoint Online Access Requests Settings with REST API/description.md @@ -4,28 +4,22 @@ Short Powershell script to retrieve the access requests settings using REST. In order to use the script, download, open the file and enter the admin's username and the site's url in the script: -PowerShell +```PowerShell #Enter the data $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="t@t321.onmicrosoft.com" $Url="https://t321.sharepoint.com/polski" - + ``` You do not need to enter the password. You will be prompted for it during script's execution. - - Sample result: - - - - - + You can also check out articles on Access Requests settings and how to manage them not only with REST, but also CSOM and User Interface: -Managing SharePoint Online Access Requests using Powershell +[Managing SharePoint Online Access Requests using Powershell](https://social.technet.microsoft.com/wiki/contents/articles/31157.manage-sharepoint-online-access-requests-using-powershell.aspxv) - SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM +[SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM](https://social.technet.microsoft.com/wiki/contents/articles/37401.sharepoint-online-approve-or-decline-access-requests-using-powershell-and-csom.aspx) diff --git a/Site Management/Get SharePoint Online Access Requests with REST API/GetSPOAccessRequestsItemsWithREST.ps1 b/Site Management/Get SharePoint Online Access Requests with REST API/GetSPOAccessRequestsItemsWithREST.ps1 index 44f3302c..3d595d38 100644 --- a/Site Management/Get SharePoint Online Access Requests with REST API/GetSPOAccessRequestsItemsWithREST.ps1 +++ b/Site Management/Get SharePoint Online Access Requests with REST API/GetSPOAccessRequestsItemsWithREST.ps1 @@ -1,54 +1,31 @@ -function Get-AccessRequests -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-AccessRequests{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string] $url - ) - - - - $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')/items" - - - - $request = [System.Net.WebRequest]::Create($RESTUrl) - $request.Credentials = $Credentials - $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") - $request.Accept = "application/json;odata=verbose" - [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get - $request.Method=$Method - $response = $request.GetResponse() - $requestStream = $response.GetResponseStream() - $read = New-Object System.IO.StreamReader $requestStream - $data=$read.ReadToEnd() - # Because the string contains duplicate 'ID' keys. - $results = $data.ToString().Replace("ID", "_ID") | ConvertFrom-Json - - - - return ($results.d.results) - - - - - - - - - } - - - - - - - - + ) + + $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')/items" + + $request = [System.Net.WebRequest]::Create($RESTUrl) + $request.Credentials = $Credentials + $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") + $request.Accept = "application/json;odata=verbose" + [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get + $request.Method=$Method + $response = $request.GetResponse() + $requestStream = $response.GetResponseStream() + $read = New-Object System.IO.StreamReader $requestStream + $data=$read.ReadToEnd() + # Because the string contains duplicate 'ID' keys. + $results = $data.ToString().Replace("ID", "_ID") | ConvertFrom-Json + + return ($results.d.results) +} #Paths to SDK Add-Type -Path "H:\Libraries\Microsoft.SharePoint.Client.dll" @@ -63,4 +40,4 @@ $Url="https://t321.sharepoint.com/polski" -Get-AccessRequests -Username $username -Url $Url -password $AdminPassword \ No newline at end of file +Get-AccessRequests -Username $username -Url $Url -password $AdminPassword diff --git a/Site Management/Get SharePoint Online Access Requests with REST API/description.md b/Site Management/Get SharePoint Online Access Requests with REST API/description.md index 36eeb63a..014acc63 100644 --- a/Site Management/Get SharePoint Online Access Requests with REST API/description.md +++ b/Site Management/Get SharePoint Online Access Requests with REST API/description.md @@ -1,32 +1,26 @@ Short Powershell script to retrieve the access requests using REST. - - In order to use the script, download, open the file and enter the admin's username and the site's url in the script: -PowerShell +```PowerShell #Enter the data $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="t@t321.onmicrosoft.com" $Url="https://t321.sharepoint.com/polski" - + ``` You do not need to enter the password. You will be prompted for it during script's execution. Sample result: - - - - - + You can also check out articles on Access Requests settings and how to manage them not only with REST, but also CSOM and User Interface: -Managing SharePoint Online Access Requests using Powershell +[Managing SharePoint Online Access Requests using Powershell](https://social.technet.microsoft.com/wiki/contents/articles/31157.manage-sharepoint-online-access-requests-using-powershell.aspx) - SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM +[SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM](https://social.technet.microsoft.com/wiki/contents/articles/37401.sharepoint-online-approve-or-decline-access-requests-using-powershell-and-csom.aspx) diff --git a/Site Management/Get SharePoint Online Site Properties/GetSiteProperties.ps1 b/Site Management/Get SharePoint Online Site Properties/GetSiteProperties.ps1 index 11f671d4..4d5eac4f 100644 --- a/Site Management/Get SharePoint Online Site Properties/GetSiteProperties.ps1 +++ b/Site Management/Get SharePoint Online Site Properties/GetSiteProperties.ps1 @@ -1,29 +1,25 @@ -function Get-SPOSiteProperties -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SPOSiteProperties{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url - ) - -# Connect and load all prerequisites - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($Username, $AdminPassword) - $ctx.ExecuteQuery() - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.AllProperties) - $ctx.ExecuteQuery() + ) - foreach ($ap in $ctx.Web.AllProperties.FieldValues) - { - Write-Output $ap - } + # Connect and load all prerequisites + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials ($Username, $AdminPassword) + $ctx.ExecuteQuery() + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.AllProperties) + $ctx.ExecuteQuery() - } + foreach ($ap in $ctx.Web.AllProperties.FieldValues){ + Write-Output $ap + } +} @@ -39,4 +35,4 @@ $SiteUrl="https://trial345.sharepoint.com/sites/teamsitewithlibraries" - Get-SPOSiteProperties -Username $Username -AdminPassword $AdminPassword -Url $SiteUrl \ No newline at end of file + Get-SPOSiteProperties -Username $Username -AdminPassword $AdminPassword -Url $SiteUrl diff --git a/Site Management/Get SharePoint Online Site Properties/description.md b/Site Management/Get SharePoint Online Site Properties/description.md index 9db73c75..6cc233b4 100644 --- a/Site Management/Get SharePoint Online Site Properties/description.md +++ b/Site Management/Get SharePoint Online Site Properties/description.md @@ -1,26 +1,18 @@ The script retrieves all properties for a Web. - - - + -Requirements - - +## *Requirements* The following script requires: -SharePoint Online SDK +[SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038) - +## *How to use?* - - -How to use? - -1. Open the following location: +**1.** Open the following location: -"c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\" +```"c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\"``` If the location exists and you can see @@ -30,34 +22,27 @@ Microsoft.SharePoint.Client.Runtime.dll Skip the next step and go to Step 3. - - -2. If the dlls are not in this location, find them, open the file with the script and correct the following paths to the locations on your computer: +**2.** If the dlls are not in this location, find them, open the file with the script and correct the following paths to the locations on your computer: - - -PowerShell +```PowerShell Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" + ``` - -3. Enter the credentials. You will be asked for password during the script's execution: - - +**3.** Enter the credentials. You will be asked for password during the script's execution: -PowerShell +```PowerShell $Username="t@trial345.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $SiteUrl="https://trial345.sharepoint.com/sites/teamsitewithlibraries" - 4. Open Powershell as Administrator. Run the script. If execution of the scripts is forbidden, you can use the cmdlet: +``` + +**4.** Open Powershell as Administrator. Run the script. If execution of the scripts is forbidden, you can use the cmdlet: -PowerShell +```PowerShell Set-ExecutionPolicy remotesigned - -5. The results will display in a 2-column table as in the screenshot above. +``` - - - +**5.** The results will display in a 2-column table as in the screenshot above. The script works for one site collection only. If you want to get properties of more sites, please check other Technet Gallery scripts. diff --git a/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/GetSPServerAccessRequestsItemsWithREST.ps1 b/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/GetSPServerAccessRequestsItemsWithREST.ps1 index 2611bf24..22bc9f81 100644 --- a/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/GetSPServerAccessRequestsItemsWithREST.ps1 +++ b/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/GetSPServerAccessRequestsItemsWithREST.ps1 @@ -1,60 +1,37 @@ -function Get-AccessRequests -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-AccessRequests{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $password, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string] $url - ) + ) - $Credentials = New-Object System.Net.NetworkCredential($Username, $password) - # $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')/items" + $Credentials = New-Object System.Net.NetworkCredential($Username, $password) + # $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $RestUrl=$url+"/_api/web/lists/getbytitle('Access Requests')/items" + $request = [System.Net.WebRequest]::Create($RESTUrl) + $request.Credentials = $Credentials + $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") + $request.Accept = "application/json;odata=verbose" + [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get + $request.Method=$Method + $response = $request.GetResponse() + $requestStream = $response.GetResponseStream() + $read = New-Object System.IO.StreamReader $requestStream + $data=$read.ReadToEnd() + # Because the string contains duplicate 'ID' keys. + $results = $data.ToString().Replace("ID", "_ID") | ConvertFrom-Json - - $request = [System.Net.WebRequest]::Create($RESTUrl) - $request.Credentials = $Credentials - $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") - $request.Accept = "application/json;odata=verbose" - [Microsoft.PowerShell.Commands.WebRequestMethod]$Method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get - $request.Method=$Method - $response = $request.GetResponse() - $requestStream = $response.GetResponseStream() - $read = New-Object System.IO.StreamReader $requestStream - $data=$read.ReadToEnd() - # Because the string contains duplicate 'ID' keys. - $results = $data.ToString().Replace("ID", "_ID") | ConvertFrom-Json + return ($results.d.results) +} - - - return ($results.d.results) - - - - - - - - - } - - - - - - - - #Enter the data $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="administrator" $Url="http://dva" - - - -Get-AccessRequests -Username $username -Url $Url -password $AdminPassword \ No newline at end of file +Get-AccessRequests -Username $username -Url $Url -password $AdminPassword diff --git a/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/description.md b/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/description.md index dbaefaac..26c441f7 100644 --- a/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/description.md +++ b/Site Management/Get SharePoint Server 2013-2016 Access Requests with REST API/description.md @@ -6,29 +6,25 @@ In order to use the script, download, open the file and enter the admin's userna -PowerShell +```PowerShell #Enter the data $AdminPassword=Read-Host -Prompt "Enter password" -AsSecureString $username="administrator" $Url="http://dva" - + ``` You do not need to enter the password. You will be prompted for it during script's execution. Sample result: - - - - - + You can also check out articles on Access Requests settings and how to manage them not only with REST, but also CSOM and User Interface: -Managing SharePoint Online Access Requests using Powershell +[Managing SharePoint Online Access Requests using Powershell](https://social.technet.microsoft.com/wiki/contents/articles/31157.manage-sharepoint-online-access-requests-using-powershell.aspx) - SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM +[SharePoint 2013/2016: Approve or decline Access Requests using Powershell and CSOM](https://social.technet.microsoft.com/wiki/contents/articles/37401.sharepoint-online-approve-or-decline-access-requests-using-powershell-and-csom.aspx) diff --git a/Site Management/Get all site collections and their subsites/GetAllSiteandSubsitesRecursive.ps1 b/Site Management/Get all site collections and their subsites/GetAllSiteandSubsitesRecursive.ps1 index 4007b4bc..fdb19a2d 100644 --- a/Site Management/Get all site collections and their subsites/GetAllSiteandSubsitesRecursive.ps1 +++ b/Site Management/Get all site collections and their subsites/GetAllSiteandSubsitesRecursive.ps1 @@ -1,31 +1,27 @@ -function Get-SPOAllWeb -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SPOAllWeb{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url - ) - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.Load($ctx.Web.Webs) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() - - Write-Host $ctx.Web.Url - if($ctx.Web.Webs.Count -eq 0) - { - - } - else{ - foreach ($web in $ctx.Web.Webs) - { - Get-SPOAllWeb -Username $Username -AdminPassword $AdminPassword -Url $web.Url - }} - + ) + + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.Load($ctx.Web.Webs) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + + Write-Host $ctx.Web.Url + + if($ctx.Web.Webs.Count -eq 0){} + else{ + foreach ($web in $ctx.Web.Webs){ + Get-SPOAllWeb -Username $Username -AdminPassword $AdminPassword -Url $web.Url + } + } } $passie=Read-Host -Prompt "Password" -AsSecureString @@ -34,15 +30,8 @@ $adminUserName=Read-Host -Prompt "Admin username" Connect-SPOService -Url $adminUrelek -Credential $adminUserName $sites=(Get-SPOSite -Limit All).Url - - -foreach($url in $sites) -{ - - Get-SPOAllWeb -Username $adminUserName -AdminPassword $passie -Url $url - - - +foreach($url in $sites){ + Get-SPOAllWeb -Username $adminUserName -AdminPassword $passie -Url $url } diff --git a/Site Management/Get all site collections and their subsites/description.md b/Site Management/Get all site collections and their subsites/description.md index 91e0d731..5ed7bc03 100644 --- a/Site Management/Get all site collections and their subsites/description.md +++ b/Site Management/Get all site collections and their subsites/description.md @@ -6,16 +6,6 @@ If you run it in ISE you can easily copy-paste the results and search through th Does not require any modifications, just open the script in any Powershell and run. It will ask you TWICE for credentials. Just follow the prompts: - - - - - - - - - - - + -Enjoy and please share your feedback!! +**Enjoy and please share your feedback!!** diff --git a/Site Management/Get all time zones from a site/GetAllTimeZones.ps1 b/Site Management/Get all time zones from a site/GetAllTimeZones.ps1 index f2b3790e..cd90f321 100644 --- a/Site Management/Get all time zones from a site/GetAllTimeZones.ps1 +++ b/Site Management/Get all time zones from a site/GetAllTimeZones.ps1 @@ -1,38 +1,28 @@  -function Get-SPOUSerTimeZones -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SPOUSerTimeZones{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.RegionalSettings.TimeZone) - $ctx.Load($ctx.Web.RegionalSettings.TimeZones) - $ctx.ExecuteQuery() - - foreach($timezone in $ctx.Web.RegionalSettings.TimeZones) - { - Write-Host $timezone.ID $timezone.Description - } + ) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.RegionalSettings.TimeZone) + $ctx.Load($ctx.Web.RegionalSettings.TimeZones) + $ctx.ExecuteQuery() - - } - - - + foreach($timezone in $ctx.Web.RegionalSettings.TimeZones){ + Write-Host $timezone.ID $timezone.Description + } +} # Paths to SDK. Please verify location on your computer. #Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" diff --git a/Site Management/Get all time zones from a site/description.md b/Site Management/Get all time zones from a site/description.md index e069c3d6..4c45c48b 100644 --- a/Site Management/Get all time zones from a site/description.md +++ b/Site Management/Get all time zones from a site/description.md @@ -1,10 +1,5 @@ Short script to retrieve all time zones from a single site in Sharepoint Online. It does not change any settings, it just lists out possible options. - - - - - The script requires the following libraries. Please make sure the paths refer correct files on you machine: @@ -23,6 +18,6 @@ $url="https://tenant-my.sharepoint.com/personal/user_tenant_onmicrosoft_com" ``` -Expected results: +## *Expected results:* 39 (UTC-12:00) International Date Line West95 (UTC-11:00) Coordinated Universal Time-1115 (UTC-10:00) Hawaii14 (UTC-09:00) Alaska78 (UTC-08:00) Baja California13 (UTC-08:00) Pacific Time (US and Canada)38 (UTC-07:00) Arizona77 (UTC-07:00) Chihuahua, La Paz, Mazatlan12 (UTC-07:00) Mountain Time (US and Canada)55 (UTC-06:00) Central America11 (UTC-06:00) Central Time (US and Canada)37 (UTC-06:00) Guadalajara, Mexico City, Monterrey36 (UTC-06:00) Saskatchewan35 (UTC-05:00) Bogota, Lima, Quito10 (UTC-05:00) Eastern Time (US and Canada)34 (UTC-05:00) Indiana (East)88 (UTC-04:30) Caracas91 (UTC-04:00) Asuncion9 (UTC-04:00) Atlantic Time (Canada)81 (UTC-04:00) Cuiaba33 (UTC-04:00) Georgetown, La Paz, Manaus, San Juan28 (UTC-03:30) Newfoundland8 (UTC-03:00) Brasilia85 (UTC-03:00) Buenos Aires32 (UTC-03:00) Cayenne, Fortaleza60 (UTC-03:00) Greenland90 (UTC-03:00) Montevideo103 (UTC-03:00) Salvador65 (UTC-03:00) Santiago96 (UTC-02:00) Coordinated Universal Time-0230 (UTC-02:00) Mid-Atlantic29 (UTC-01:00) Azores53 (UTC-01:00) Cabo Verde86 (UTC) Casablanca93 (UTC) Coordinated Universal Time2 (UTC) Dublin, Edinburgh, Lisbon, London31 (UTC) Monrovia, Reykjavik4 (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna6 (UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague3 (UTC+01:00) Brussels, Copenhagen, Madrid, Paris57 (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb69 (UTC+01:00) West Central Africa83 (UTC+01:00) Windhoek79 (UTC+02:00) Amman5 (UTC+02:00) Athens, Bucharest, Istanbul80 (UTC+02:00) Beirut49 (UTC+02:00) Cairo98 (UTC+02:00) Damascus50 (UTC+02:00) Harare, Pretoria59 (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius101 (UTC+02:00) Istanbul27 (UTC+02:00) Jerusalem7 (UTC+02:00) Minsk (old)104 (UTC+02:00) E. Europe100 (UTC+02:00) Kaliningrad (RTZ 1)26 (UTC+03:00) Baghdad74 (UTC+03:00) Kuwait, Riyadh109 (UTC+03:00) Minsk51 (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2)56 (UTC+03:00) Nairobi25 (UTC+03:30) Tehran24 (UTC+04:00) Abu Dhabi, Muscat54 (UTC+04:00) Baku106 (UTC+04:00) Izhevsk, Samara (RTZ 3)89 (UTC+04:00) Port Louis82 (UTC+04:00) Tbilisi84 (UTC+04:00) Yerevan48 (UTC+04:30) Kabul58 (UTC+05:00) Ekaterinburg (RTZ 4)87 (UTC+05:00) Islamabad, Karachi47 (UTC+05:00) Tashkent23 (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi66 (UTC+05:30) Sri Jayawardenepura62 (UTC+05:45) Kathmandu71 (UTC+06:00) Astana102 (UTC+06:00) Dhaka46 (UTC+06:00) Novosibirsk (RTZ 5)61 (UTC+06:30) Yangon (Rangoon)22 (UTC+07:00) Bangkok, Hanoi, Jakarta64 (UTC+07:00) Krasnoyarsk (RTZ 6)45 (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi63 (UTC+08:00) Irkutsk (RTZ 7)21 (UTC+08:00) Kuala Lumpur, Singapore73 (UTC+08:00) Perth75 (UTC+08:00) Taipei94 (UTC+08:00) Ulaanbaatar20 (UTC+09:00) Osaka, Sapporo, Tokyo72 (UTC+09:00) Seoul70 (UTC+09:00) Yakutsk (RTZ 8)19 (UTC+09:30) Adelaide44 (UTC+09:30) Darwin18 (UTC+10:00) Brisbane76 (UTC+10:00) Canberra, Melbourne, Sydney43 (UTC+10:00) Guam, Port Moresby42 (UTC+10:00) Hobart99 (UTC+10:00) Magadan68 (UTC+10:00) Vladivostok, Magadan (RTZ 9)107 (UTC+11:00) Chokurdakh (RTZ 10)41 (UTC+11:00) Solomon Is., New Caledonia108 (UTC+12:00) Anadyr, Petropavlovsk-Kamchatsky (RTZ 11)17 (UTC+12:00) Auckland, Wellington97 (UTC+12:00) Coordinated Universal Time+1240 (UTC+12:00) Fiji92 (UTC+12:00) Petropavlovsk-Kamchatsky - Old67 (UTC+13:00) Nuku'alofa16 (UTC+13:00) Samoa diff --git a/Site Management/Get-SPOWeb to retrieve subsites and their properties/GetSPOWebModule.psm1 b/Site Management/Get-SPOWeb to retrieve subsites and their properties/GetSPOWebModule.psm1 index 4343f853..d3a58b79 100644 --- a/Site Management/Get-SPOWeb to retrieve subsites and their properties/GetSPOWebModule.psm1 +++ b/Site Management/Get-SPOWeb to retrieve subsites and their properties/GetSPOWebModule.psm1 @@ -1,71 +1,57 @@ -function Get-SPOWeb -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-SPOWeb{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword, - [Parameter(Mandatory=$false,Position=4)] + [Parameter(Mandatory=$false,Position=4)] [bool]$IncludeSubsites=$false - ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) - $ctx.ExecuteQuery() - - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - $obj = new-Object PSOBject - $obj | Add-Member NoteProperty AllowRSSFeeds($ctx.Web.Webs[$i].AllowRssFeeds) - $obj | Add-Member NoteProperty Created($ctx.Web.Webs[$i].Created) - $obj | Add-Member NoteProperty CustomMasterUrl($ctx.Web.Webs[$i].CustomMasterUrl) - $obj | Add-Member NoteProperty Description($ctx.Web.Webs[$i].Description) - $obj | Add-Member NoteProperty EnableMinimalDownload($ctx.Web.Webs[$i].EnableMinimalDownload) - $obj | Add-Member NoteProperty ID($ctx.Web.Webs[$i].Id) - $obj | Add-Member NoteProperty Language($ctx.Web.Webs[$i].Language) - $obj | Add-Member NoteProperty LastItemModifiedDate($ctx.Web.Webs[$i].LastItemModifiedDate) - $obj | Add-Member NoteProperty MasterUrl($ctx.Web.Webs[$i].MasterUrl) - $obj | Add-Member NoteProperty QuickLaunchEnabled($ctx.Web.Webs[$i].QuickLaunchEnabled) - $obj | Add-Member NoteProperty RecycleBinEnabled($ctx.Web.Webs[$i].RecycleBinEnabled) - $obj | Add-Member NoteProperty ServerRelativeUrl($ctx.Web.Webs[$i].ServerRelativeUrl) - $obj | Add-Member NoteProperty Title($ctx.Web.Webs[$i].Title) - $obj | Add-Member NoteProperty TreeViewEnabled($ctx.Web.Webs[$i].TreeViewEnabled) - $obj | Add-Member NoteProperty UIVersion($ctx.Web.Webs[$i].UIVersion) - $obj | Add-Member NoteProperty UIVersionConfigurationEnabled($ctx.Web.Webs[$i].UIVersionConfigurationEnabled) - $obj | Add-Member NoteProperty Url($ctx.Web.Webs[$i].Url) - $obj | Add-Member NoteProperty WebTemplate($ctx.Web.Webs[$i].WebTemplate) - - Write-Output $obj - } - - - -if($ctx.Web.Webs.Count -gt 0 -and $IncludeSubsites) - { - Write-Host "--"-ForegroundColor DarkGreen - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - Get-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -IncludeSubsites $IncludeSubsites - } - } - - - - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + $obj = new-Object PSOBject + $obj | Add-Member NoteProperty AllowRSSFeeds($ctx.Web.Webs[$i].AllowRssFeeds) + $obj | Add-Member NoteProperty Created($ctx.Web.Webs[$i].Created) + $obj | Add-Member NoteProperty CustomMasterUrl($ctx.Web.Webs[$i].CustomMasterUrl) + $obj | Add-Member NoteProperty Description($ctx.Web.Webs[$i].Description) + $obj | Add-Member NoteProperty EnableMinimalDownload($ctx.Web.Webs[$i].EnableMinimalDownload) + $obj | Add-Member NoteProperty ID($ctx.Web.Webs[$i].Id) + $obj | Add-Member NoteProperty Language($ctx.Web.Webs[$i].Language) + $obj | Add-Member NoteProperty LastItemModifiedDate($ctx.Web.Webs[$i].LastItemModifiedDate) + $obj | Add-Member NoteProperty MasterUrl($ctx.Web.Webs[$i].MasterUrl) + $obj | Add-Member NoteProperty QuickLaunchEnabled($ctx.Web.Webs[$i].QuickLaunchEnabled) + $obj | Add-Member NoteProperty RecycleBinEnabled($ctx.Web.Webs[$i].RecycleBinEnabled) + $obj | Add-Member NoteProperty ServerRelativeUrl($ctx.Web.Webs[$i].ServerRelativeUrl) + $obj | Add-Member NoteProperty Title($ctx.Web.Webs[$i].Title) + $obj | Add-Member NoteProperty TreeViewEnabled($ctx.Web.Webs[$i].TreeViewEnabled) + $obj | Add-Member NoteProperty UIVersion($ctx.Web.Webs[$i].UIVersion) + $obj | Add-Member NoteProperty UIVersionConfigurationEnabled($ctx.Web.Webs[$i].UIVersionConfigurationEnabled) + $obj | Add-Member NoteProperty Url($ctx.Web.Webs[$i].Url) + $obj | Add-Member NoteProperty WebTemplate($ctx.Web.Webs[$i].WebTemplate) + + Write-Output $obj + } + + if($ctx.Web.Webs.Count -gt 0 -and $IncludeSubsites){ + Write-Host "--"-ForegroundColor DarkGreen + + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + Get-SPOWeb -Username $Username -Url $ctx.Web.Webs[$i].Url -AdminPassword $AdminPassword -IncludeSubsites $IncludeSubsites + } + } } Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - - Export-ModuleMember -Function "Get-SPOWeb" diff --git a/Site Management/Get-SPOWeb to retrieve subsites and their properties/description.md b/Site Management/Get-SPOWeb to retrieve subsites and their properties/description.md index 8bd88fb8..77d8bbaf 100644 --- a/Site Management/Get-SPOWeb to retrieve subsites and their properties/description.md +++ b/Site Management/Get-SPOWeb to retrieve subsites and their properties/description.md @@ -1,98 +1,66 @@ -The cmdlet Get-SPOWeb retrieves subsites and their properties +The cmdlet **Get-SPOWeb** retrieves subsites and their properties - - -Parameters +## Parameters The cmdlet is using the following parameters: - [string]$Username +- [string]$Username + The string specifies admin of the site -[string]$Url +- [string]$Url + Specifies the url of the parent site -[string]$AdminPassword, +- [string]$AdminPassword, + Admin's password -[bool]$IncludeSubsites=$false -Specifies whether the sub-subsites and subs-subsubsites should be included as well. By default set to $false. +- [bool]$IncludeSubsites=$false - +Specifies whether the sub-subsites and subs-subsubsites should be included as well. By default set to $false. -Examples +## Examples - +- Get the subsites and their properties -Get the subsites and their properties Get-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -AdminPassword Pass -Url https://trialtrial123.sharepoint.com + +- Get the subsites and the sub-subsites - - - - - - - - -Get the subsites and the sub-subsites Get-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -AdminPassword Pass -Url https://trialtrial123.sharepoint.com -IncludeSubsites $true | select url - + +- Get properties of a site in the site collection - - - - - -Get properties of a site in the site collection Get-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -AdminPassword Pass -Url https://trialtrial123.sharepoint.com -IncludeSubsites $true | where {$_.Title -eq "SomeTitle"} - - - + - - - +- Get all sites in a site collecton based on some criteria - - -Get all sites in a site collecton based on some criteria Get-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -AdminPassword Pass -Url https://trialtrial123.sharepoint.com -IncludeSubsites $true | where {$_.Language -eq 1033} | select url - - - - - - - - - - - +

Requirements

- - The following libraries (SharePoint Online SDK) are required. If those libraries are in different location on your computer, please edit the .psm1 file! -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - + ``` -Let me know about your experience in the Q&A section! +### Let me know about your experience in the Q&A section! diff --git a/Site Management/Modify Web Inherited Permissions/SPOWebInheritance.psm1 b/Site Management/Modify Web Inherited Permissions/SPOWebInheritance.psm1 index ce2fa9f4..d546a3b6 100644 --- a/Site Management/Modify Web Inherited Permissions/SPOWebInheritance.psm1 +++ b/Site Management/Modify Web Inherited Permissions/SPOWebInheritance.psm1 @@ -1,76 +1,62 @@ -function Remove-SPOWebInheritance -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Remove-SPOWebInheritance{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword, - [Parameter(Mandatory=$false,Position=4)] + [Parameter(Mandatory=$false,Position=4)] [bool]$CopyRoleAssignments=$true, - [Parameter(Mandatory=$false,Position=5)] + [Parameter(Mandatory=$false,Position=5)] [bool]$clearSubscopes=$false - ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() - - try - { - $ctx.Web.BreakRoleInheritance($CopyRoleAssignments,$clearSubscopes) - $ctx.ExecuteQuery() - Write-Host "Site " $ctx.Web.Url " has unique permissions." - } - catch [Net.WebException] - { - Write-Host $_.Exception.ToString() - } - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + + try{ + $ctx.Web.BreakRoleInheritance($CopyRoleAssignments,$clearSubscopes) + $ctx.ExecuteQuery() + Write-Host "Site " $ctx.Web.Url " has unique permissions." + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } } -function Restore-SPOWebInheritance -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Restore-SPOWebInheritance{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword - ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() - - try - { - $ctx.Web.ResetRoleInheritance() - $ctx.ExecuteQuery() - Write-Host "Site " $ctx.Web.Url " inherits permissions from its parent." - } - catch [Net.WebException] - { - Write-Host $_.Exception.ToString() - } - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + + try{ + $ctx.Web.ResetRoleInheritance() + $ctx.ExecuteQuery() + Write-Host "Site " $ctx.Web.Url " inherits permissions from its parent." + } + catch [Net.WebException]{ + Write-Host $_.Exception.ToString() + } } Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - - - Export-ModuleMember -Function "Restore-SPOWebInheritance", "Remove-SPOWebInheritance" \ No newline at end of file + Export-ModuleMember -Function "Restore-SPOWebInheritance", "Remove-SPOWebInheritance" diff --git a/Site Management/Modify Web Inherited Permissions/description.md b/Site Management/Modify Web Inherited Permissions/description.md index 5627de15..acd4659e 100644 --- a/Site Management/Modify Web Inherited Permissions/description.md +++ b/Site Management/Modify Web Inherited Permissions/description.md @@ -1,122 +1,81 @@ Powershell Module with 2 new cmdlets: - - Remove-SPOWebInheritance Restore-SPOWebInheritance - - - - -Restore-SPOWebInheritance - - - - +--- +## Restore-SPOWebInheritance -Parameters +### Parameters The cmdlet is using the following parameters: - [string]$Username -The string specifies admin of the site - -[string]$ParentUrl -Specifies the url of the parent site - -[string]$AdminPassword, - +- [string]$Username - - - +The string specifies admin of the site - +- [string]$ParentUrl -Remove-SPOWebInheritance +Specifies the url of the parent site +- [string]$AdminPassword, +--- +## Remove-SPOWebInheritance -Parameters +##Parameters The cmdlet is using the following parameters: - [string]$Username +- [string]$Username + The string specifies admin of the site -[string]$ParentUrl -Specifies the url of the parent site +- [string]$ParentUrl -[string]$AdminPassword, -Admin's password +Specifies the url of the parent site -[bool]$CopyRoleAssignments=$true -Whether the site should keep its current permissions +- [string]$AdminPassword, - [bool]$clearSubscopes=$false - +Admin's password - +- [bool]$CopyRoleAssignments=$true -Examples +Whether the site should keep its current permissions +- [bool]$clearSubscopes=$false +--- +## Examples -Restore-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass +**Restore-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass** Site https://trialtrial123.sharepoint.com/psweb2/psweb2 inherits permissions from its parent. - - -Remove-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -CopyRoleAssignments $true - +**Remove-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -CopyRoleAssignments $true** - - - - + That gives us: - - - - - - - - - - - + But if we set the CopyRoleAssignments to $false: -Remove-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -CopyRoleAssignments $false - - - +**Remove-SPOWebInheritance -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -CopyRoleAssignments $false** + - - -Requirements - - +### *Requirements* The following libraries (SharePoint Online SDK) are required. If those libraries are in different location on your computer, please edit the .psm1 file! - - - - -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - -Let me know about your experience in the Q&A section! + ``` +### Let me know about your experience in the Q&A section! diff --git a/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/Set-SPOWeb.psm1 b/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/Set-SPOWeb.psm1 index d54287a9..3c49d926 100644 --- a/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/Set-SPOWeb.psm1 +++ b/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/Set-SPOWeb.psm1 @@ -1,89 +1,70 @@ -function Set-SPOWeb -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOWeb{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$AdminPassword, - [Parameter(Mandatory=$false,Position=4)] + [Parameter(Mandatory=$false,Position=4)] [string]$Description="", -[ValidateSet("True","False","", 0, 1)] -[Parameter(Mandatory=$false,Position=5)] + [ValidateSet("True","False","", 0, 1)] + [Parameter(Mandatory=$false,Position=5)] [string]$EnableMinimalDownload="", -[ValidateSet("True","False","", 0, 1)] -[Parameter(Mandatory=$false,Position=6)] + [ValidateSet("True","False","", 0, 1)] + [Parameter(Mandatory=$false,Position=6)] [string]$QuickLaunchEnabled="", -[Parameter(Mandatory=$false,Position=7)] + [Parameter(Mandatory=$false,Position=7)] [string]$Title="", -[ValidateSet("True","False","", 0, 1)] -[Parameter(Mandatory=$false,Position=8)] + [ValidateSet("True","False","", 0, 1)] + [Parameter(Mandatory=$false,Position=8)] [string]$TreeViewEnabled="" - ) - -$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() - - - - if($Description -ne "") - { - $ctx.Web.Description = $Description - $ctx.Web.Update() - $ctx.ExecuteQuery() - Write-Host "Description set to " $Description -ForegroundColor Green - } - - - if($EnableMinimalDownload -ne "") - { - $ctx.Web.EnableMinimalDownload = $EnableMinimalDownload - $ctx.Web.Update() - $ctx.ExecuteQuery() - Write-Host "Minimal Download set to " $EnableMinimalDownload -ForegroundColor Green - } - - if($QuickLaunchEnabled -ne "") - { - - $ctx.Web.QuickLaunchEnabled = $QuickLaunchEnabled - $ctx.Web.Update() - $ctx.ExecuteQuery() - Write-Host "Quick launch set to " $QuickLaunchEnabled -ForegroundColor Green - } - - - - - if($Title -ne "") - { - $ctx.Web.Title = $Title - $ctx.Web.Update() - $ctx.ExecuteQuery() - Write-Host "Title set to " $Title -ForegroundColor Green - } - - if($TreeViewEnabled -ne "") - { - $ctx.Web.TreeViewEnabled = $TreeViewEnabled - $ctx.Web.Update() - $ctx.ExecuteQuery() - Write-Host "Treeview set to " $TreeViewEnabled -ForegroundColor Green - } - - + ) + + $password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + + if($Description -ne ""){ + $ctx.Web.Description = $Description + $ctx.Web.Update() + $ctx.ExecuteQuery() + Write-Host "Description set to " $Description -ForegroundColor Green + } + + + if($EnableMinimalDownload -ne ""){ + $ctx.Web.EnableMinimalDownload = $EnableMinimalDownload + $ctx.Web.Update() + $ctx.ExecuteQuery() + Write-Host "Minimal Download set to " $EnableMinimalDownload -ForegroundColor Green + } + + if($QuickLaunchEnabled -ne ""){ + $ctx.Web.QuickLaunchEnabled = $QuickLaunchEnabled + $ctx.Web.Update() + $ctx.ExecuteQuery() + Write-Host "Quick launch set to " $QuickLaunchEnabled -ForegroundColor Green + } + + if($Title -ne ""){ + $ctx.Web.Title = $Title + $ctx.Web.Update() + $ctx.ExecuteQuery() + Write-Host "Title set to " $Title -ForegroundColor Green + } + + if($TreeViewEnabled -ne ""){ + $ctx.Web.TreeViewEnabled = $TreeViewEnabled + $ctx.Web.Update() + $ctx.ExecuteQuery() + Write-Host "Treeview set to " $TreeViewEnabled -ForegroundColor Green + } } - Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - - Export-ModuleMember -Function "Set-SPOWeb" diff --git a/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/description.md b/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/description.md index 16668dbd..68abda5d 100644 --- a/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/description.md +++ b/Site Management/Powershell cmdlet Set-SpoWeb to manage site properties/description.md @@ -1,78 +1,69 @@ SharePoint Online cmdlet - - -Set-SPOWeb - - +--- +## Set-SPOWeb

Parameters

The cmdlet is using the following parameters: - [string]$Username +- [string]$Username + The string specifies admin of the site -[string]$Url +- [string]$Url + Specifies the url of the parent site -[string]$AdminPassword, +- [string]$AdminPassword, + Admin's password -[string]$Description="" +- [string]$Description="" + Optional. -[string]$EnableMinimalDownload="" +- [string]$EnableMinimalDownload="" + Optional. -[string]$QuickLaunchEnabled="" +- [string]$QuickLaunchEnabled="" + Optional -[string]$Title="" -Optional. +- [string]$Title="" -[string]$TreeViewEnabled="" Optional. - +- [string]$TreeViewEnabled="" - +Optional.

Examples

- +- Set the site description and title -Set the site description and title Set-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -Description "none" -Title "Sososos23"Description set to noneTitle set to Sososos23PS -Enable tree view for the site -Set-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -TreeViewEnabled $true +- Enable tree view for the site - +Set-SPOWeb -Username trial@trialtrial123.onmicrosoft.com -Url https://trialtrial123.sharepoint.com/psweb2/psweb2 -AdminPassword Pass -TreeViewEnabled $true +

Requirements

- - The following libraries (SharePoint Online SDK) are required. If those libraries are in different location on your computer, please edit the .psm1 file! -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" - - - - - - - - +``` -Let me know about your experience in the Q&A section! +### Let me know about your experience in the Q&A section! diff --git a/Site Management/Recycle Bin/Detailed report on all recycle bin items across all site collections/description.md b/Site Management/Recycle Bin/Detailed report on all recycle bin items across all site collections/description.md index b95849cf..39912046 100644 --- a/Site Management/Recycle Bin/Detailed report on all recycle bin items across all site collections/description.md +++ b/Site Management/Recycle Bin/Detailed report on all recycle bin items across all site collections/description.md @@ -1,57 +1,29 @@ The script loops through all site collections, their subsites and retrieves all items from the recycle bin. The items can be seen in the console window or you can create an Excel report *doesn't apply to group site collections or personal sites - - -The script is basically an extension of a more basic Retrieve all reycle bin items across all site collections script. +The script is basically an extension of a more basic [Retrieve all reycle bin items across all site collections](https://gallery.technet.microsoft.com/Retrieve-all-reycle-bin-66bcab5c) script. The script loops through all site collections, their subsites and retrieves all items from the recycle bin and restores them. The items can be seen in the console window - - - - - - - - - + or you can create an Excel report using | Export-csv -c:\users\MyUser\Desktop\whereismyfilewithdetails.ps1 | export-csv c:\users\ivo\desktop\whereismyfilewithdetails2.csv - - - - - - - - - - +```c:\users\MyUser\Desktop\whereismyfilewithdetails.ps1 | export-csv c:\users\ivo\desktop\whereismyfilewithdetails2.csv``` + - The script requires SharePoint Online Management Shell and SharePoint Online SDK: http://technet.microsoft.com/en-us/library/fp161372(v=office.15).aspx http://www.microsoft.com/en-us/download/details.aspx?id=30722 - - - - Before running the script enter correct paths to the SDK and your tenant data: - - - - ```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" diff --git a/Site Management/Recycle Bin/Move items from first to second stage recycle bin/MovingtoSecondStage.ps1 b/Site Management/Recycle Bin/Move items from first to second stage recycle bin/MovingtoSecondStage.ps1 index 3eb7fa9a..c631b7a7 100644 --- a/Site Management/Recycle Bin/Move items from first to second stage recycle bin/MovingtoSecondStage.ps1 +++ b/Site Management/Recycle Bin/Move items from first to second stage recycle bin/MovingtoSecondStage.ps1 @@ -1,38 +1,36 @@ # The following script moves all items from a site collection and the specified subsite into second-stage recycle bin. -function Move-ToSecondStage -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Move-ToSecondStage{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) -# $ctx.Load($ctx.Site) - $rb=$ctx.Web.RecycleBin -# $siteRB=$ctx.Site.RecycleBin -$ctx.Load($rb) -#$ctx.load($siteRB) -$ctx.ExecuteQuery() -Write-Host $ctx.Web.Url " has " $rb.Count.ToString() " items in the recycle bin" -#Write-Host $ctx.Site.Url " has " $SiteRB.Count.ToString() " items in the recycle bin" - -Write-Host "Moving items to the second stage recycle bin..." -#$siteRB.MoveAllToSecondStage() -$rb.MoveAllToSecondStage() - -$ctx.ExecuteQuery() - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + # $ctx.Load($ctx.Site) + $rb=$ctx.Web.RecycleBin + # $siteRB=$ctx.Site.RecycleBin + $ctx.Load($rb) + #$ctx.load($siteRB) + $ctx.ExecuteQuery() + Write-Host $ctx.Web.Url " has " $rb.Count.ToString() " items in the recycle bin" + #Write-Host $ctx.Site.Url " has " $SiteRB.Count.ToString() " items in the recycle bin" + + Write-Host "Moving items to the second stage recycle bin..." + #$siteRB.MoveAllToSecondStage() + $rb.MoveAllToSecondStage() + + $ctx.ExecuteQuery() } diff --git a/Site Management/Recycle Bin/Move items from first to second stage recycle bin/description.md b/Site Management/Recycle Bin/Move items from first to second stage recycle bin/description.md index 31b5e4f3..75587eec 100644 --- a/Site Management/Recycle Bin/Move items from first to second stage recycle bin/description.md +++ b/Site Management/Recycle Bin/Move items from first to second stage recycle bin/description.md @@ -1,27 +1,13 @@ Powershell script which moves all items from a site's recycle bin to a second stage recycle bin: - - - + After the move the items can still be restored using 'Restore Selection' button. - - - - - - - - The script requires SharePoint Online SDK installed: https://www.microsoft.com/en-us/download/details.aspx?id=42038 - - - - Before running the script, open the file and enter correct paths to the SDK and your tenant data: diff --git a/Site Management/Recycle Bin/Remove all items from second stage recycle bin (involves data loss)/RemovingSecondStage.ps1 b/Site Management/Recycle Bin/Remove all items from second stage recycle bin (involves data loss)/RemovingSecondStage.ps1 index 217f1b07..80fdecfe 100644 --- a/Site Management/Recycle Bin/Remove all items from second stage recycle bin (involves data loss)/RemovingSecondStage.ps1 +++ b/Site Management/Recycle Bin/Remove all items from second stage recycle bin (involves data loss)/RemovingSecondStage.ps1 @@ -1,36 +1,34 @@ # The following script permanently removes all items from a site collection second-stage recycle bin. # The items cannot be retrieved afterwards with Powershell, User Interface, or any programmatic way. -function Remove-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Remove-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Site) - $rb=$ctx.Web.RecycleBin - $siteRB=$ctx.Site.RecycleBin -$ctx.Load($rb) -$ctx.load($siteRB) -$ctx.ExecuteQuery() -Write-Host $ctx.Web.Url " has " $rb.Count.ToString() " items in the recycle bin" -Write-Host $ctx.Site.Url " has " $SiteRB.Count.ToString() " items in the recycle bin" - -Write-Host "Removing second stage items..." -$siteRB.DeleteAllSecondStageItems() -$ctx.ExecuteQuery() - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Site) + $rb=$ctx.Web.RecycleBin + $siteRB=$ctx.Site.RecycleBin + $ctx.Load($rb) + $ctx.load($siteRB) + $ctx.ExecuteQuery() + Write-Host $ctx.Web.Url " has " $rb.Count.ToString() " items in the recycle bin" + Write-Host $ctx.Site.Url " has " $SiteRB.Count.ToString() " items in the recycle bin" + + Write-Host "Removing second stage items..." + $siteRB.DeleteAllSecondStageItems() + $ctx.ExecuteQuery() } diff --git a/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/DeleteAll.ps1 b/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/DeleteAll.ps1 index 158874cc..887c8a69 100644 --- a/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/DeleteAll.ps1 +++ b/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/DeleteAll.ps1 @@ -7,38 +7,36 @@ its corresponding site collection recycle bin. The data cannot be retrieved afte Test the script before using on production environment. #> -function Remove-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Remove-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Site) - $rb=$ctx.Web.RecycleBin - $siteRB=$ctx.Site.RecycleBin -$ctx.Load($rb) -$ctx.load($siteRB) -$ctx.ExecuteQuery() -Write-Host $ctx.Web.Url $rb.Count.ToString() -Write-Host $ctx.Site.Url $SiteRB.Count.ToString() - -$rb.DeleteAll() -$siteRB.DeleteAll() -$siteRB.DeleteAllSecondStageItems() - -$ctx.ExecuteQuery() - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Site) + $rb=$ctx.Web.RecycleBin + $siteRB=$ctx.Site.RecycleBin + $ctx.Load($rb) + $ctx.load($siteRB) + $ctx.ExecuteQuery() + Write-Host $ctx.Web.Url $rb.Count.ToString() + Write-Host $ctx.Site.Url $SiteRB.Count.ToString() + + $rb.DeleteAll() + $siteRB.DeleteAll() + $siteRB.DeleteAllSecondStageItems() + + $ctx.ExecuteQuery() } diff --git a/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/description.md b/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/description.md index 68f74faf..27b37316 100644 --- a/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/description.md +++ b/Site Management/Recycle Bin/Remove permanently all items from recycle bins (data loss involved)/description.md @@ -1,12 +1,8 @@ The script removes permanently and irrevocably items from the specified site recycle bin and its corresponding site collection recycle bin. The data cannot be retrieved afterwards. Test the script before using on production environment. - - - - -PowerShell +```PowerShell $ctx.Load($ctx.Web) $ctx.Load($ctx.Site) $rb=$ctx.Web.RecycleBin @@ -22,19 +18,12 @@ $siteRB.DeleteAll() $siteRB.DeleteAllSecondStageItems() $ctx.ExecuteQuery() - - - - + ``` The script requires SharePoint Online SDK installed: https://www.microsoft.com/en-us/download/details.aspx?id=42038 - - - - Before running the script, open the file and enter correct paths to the SDK and your tenant data: diff --git a/Site Management/Recycle Bin/Report on all deleted items across all site collections/WhereIsMyFileWithDetails3.ps1 b/Site Management/Recycle Bin/Report on all deleted items across all site collections/WhereIsMyFileWithDetails3.ps1 index bc4374f1..0e8291a9 100644 --- a/Site Management/Recycle Bin/Report on all deleted items across all site collections/WhereIsMyFileWithDetails3.ps1 +++ b/Site Management/Recycle Bin/Report on all deleted items across all site collections/WhereIsMyFileWithDetails3.ps1 @@ -1,60 +1,45 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ -$ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) - $ctx.Load($ctx.Web.Webs) - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -try -{ -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url $rb.Count.ToString() -} catch [Net.WebException] - { - - Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red - -} - -for($i=0;$i -lt $rb.Count ;$i++) -{ - - $ctx.Load($rb[$i].Author) - $ctx.Load($rb[$i].DeletedBy) - $ctx.ExecuteQuery() - $obj = $rb[$i] - $obj | Add-Member NoteProperty AuthorLoginName($rb[$i].Author.LoginName) - $obj | Add-Member NoteProperty DeletedByLoginName($rb[$i].DeletedBy.LoginName) - Write-Output $obj - - -} - - - - - - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $ctx.Load($ctx.Web.Webs) + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + + try{ + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url $rb.Count.ToString() + } + catch [Net.WebException] { + Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red + } + + for($i=0;$i -lt $rb.Count ;$i++){ + $ctx.Load($rb[$i].Author) + $ctx.Load($rb[$i].DeletedBy) + $ctx.ExecuteQuery() + $obj = $rb[$i] + $obj | Add-Member NoteProperty AuthorLoginName($rb[$i].Author.LoginName) + $obj | Add-Member NoteProperty DeletedByLoginName($rb[$i].DeletedBy.LoginName) + Write-Output $obj + } } @@ -71,11 +56,8 @@ $AdminUrl="https://tenant-admin.sharepoint.com" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site } diff --git a/Site Management/Recycle Bin/Report on all deleted items across all site collections/description.md b/Site Management/Recycle Bin/Report on all deleted items across all site collections/description.md index 6817e5bd..5ee9b259 100644 --- a/Site Management/Recycle Bin/Report on all deleted items across all site collections/description.md +++ b/Site Management/Recycle Bin/Report on all deleted items across all site collections/description.md @@ -1,40 +1,26 @@ The script loops through all site collections recycle bins and prints out the deleted items details or creates an Excel report on them -* doesn't apply to group site collections or personal sites +* doesn't apply to group site collections or personal sites - - -The script is basically an extension of a more basic Retrieve all reycle bin items across all site collections script, but it does NOT restore the items. +The script is basically an extension of a more basic [Retrieve all reycle bin items across all site collections](https://gallery.technet.microsoft.com/Retrieve-all-reycle-bin-66bcab5c) script, but it does NOT restore the items. The script loops through all site collections, their subsites and retrieves all items from the recycle bin. The items can be seen in the console window - + or you can create an Excel report using | Export-csv c:\users\MyUser\Desktop\whereismyfilewithdetails3.ps1 | export-csv c:\users\ivo\desktop\whereismyfilewithdetails2.csv - - + - - - - -The script requires SharePoint Online Management Shell and SharePoint Online SDK - - - - +The script requires [SharePoint Online Management Shell](https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?view=sharepoint-ps&redirectedfrom=MSDN) and [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038) Before running the script enter correct paths to the SDK and your tenant data: - - - -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -43,5 +29,5 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="user@tenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://tenant-admin.sharepoint.com" - + ``` diff --git a/Site Management/Recycle Bin/Report on deleted files within one site/ReportOnDeleted.ps1 b/Site Management/Recycle Bin/Report on deleted files within one site/ReportOnDeleted.ps1 index c26a2789..4b42e489 100644 --- a/Site Management/Recycle Bin/Report on deleted files within one site/ReportOnDeleted.ps1 +++ b/Site Management/Recycle Bin/Report on deleted files within one site/ReportOnDeleted.ps1 @@ -1,38 +1,30 @@ -function Get-DeletedItem -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItem{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Site) - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -$ctx.ExecuteQuery() - -for($i=0;$i -lt $rb.Count ;$i++) -{ - $obj = $rb[$i] - - Write-Output $obj - - -} -#$ctx.Web.RecycleBin.RestoreAll() -$ctx.ExecuteQuery() - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + $ctx.Load($ctx.Site) + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + $ctx.ExecuteQuery() + for($i=0;$i -lt $rb.Count ;$i++){ + $obj = $rb[$i] + Write-Output $obj + } + #$ctx.Web.RecycleBin.RestoreAll() + $ctx.ExecuteQuery() } diff --git a/Site Management/Recycle Bin/Report on deleted files within one site/description.md b/Site Management/Recycle Bin/Report on deleted files within one site/description.md index 747e744e..23d56957 100644 --- a/Site Management/Recycle Bin/Report on deleted files within one site/description.md +++ b/Site Management/Recycle Bin/Report on deleted files within one site/description.md @@ -2,27 +2,13 @@ Powershell script that lists all files and items deleted from a single site and Powershell script that lists all files and items deleted from a single site and present in the recycle bin of that site. - - -Works with group sites! - - +**Works with group sites!** - - - +The script requires [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038). After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: - +(usually if not, they will be under **16**\ISAPI\) - - -The script requires SharePoint Online SDK. After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: - -(usually if not, they will be under 16\ISAPI\) - - - -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -31,7 +17,7 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="2190@sampletenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://sampletenant.sharepoint.com/sites/dgd" - +``` Insert the credentials before running the script. @@ -40,7 +26,7 @@ Insert the credentials before running the script. You can either view the deleted files in the Powershell console or enter: -PathToTheFile\ReportOnDeleted.ps1| export-csv c:\users\MyUSer\CSVReport.csv +**PathToTheFile\ReportOnDeleted.ps1| export-csv c:\users\MyUSer\CSVReport.csv** diff --git a/Site Management/Recycle Bin/Restore All Files from a Given Site/RestoreAllDeletedGroupFiles.ps1 b/Site Management/Recycle Bin/Restore All Files from a Given Site/RestoreAllDeletedGroupFiles.ps1 index 0ddd35c8..8a48455a 100644 --- a/Site Management/Recycle Bin/Restore All Files from a Given Site/RestoreAllDeletedGroupFiles.ps1 +++ b/Site Management/Recycle Bin/Restore All Files from a Given Site/RestoreAllDeletedGroupFiles.ps1 @@ -1,29 +1,24 @@ -function Restore-AllItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Restore-AllItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url $rb.Count.ToString() -$ctx.Site.RecycleBin.RestoreAll() -$ctx.ExecuteQuery() - - - - - + ) + + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url $rb.Count.ToString() + $ctx.Site.RecycleBin.RestoreAll() + $ctx.ExecuteQuery() } diff --git a/Site Management/Recycle Bin/Restore All Files from a Given Site/description.md b/Site Management/Recycle Bin/Restore All Files from a Given Site/description.md index cfa62e88..b6bc59f7 100644 --- a/Site Management/Recycle Bin/Restore All Files from a Given Site/description.md +++ b/Site Management/Recycle Bin/Restore All Files from a Given Site/description.md @@ -1,26 +1,16 @@ Powershell script that loops through all files and items deleted from a single site and present in the recycle bin of that site. All files are restored. - - -Works with group sites! - - - - - - - - +**Works with group sites!** -The script requires SharePoint Online SDK. After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: +The script requires [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038). After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: -(usually if not, they will be under 16\ISAPI\) +(usually if not, they will be under **16**\ISAPI\) -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -29,5 +19,6 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="2190@sampletenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://sampletenant.sharepoint.com/sites/dgd" +``` Insert the credentials before running the script. diff --git a/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/WhereIsMyFileWithDetails3BasedRestore.ps1 b/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/WhereIsMyFileWithDetails3BasedRestore.ps1 index 2a6164b5..f6327f51 100644 --- a/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/WhereIsMyFileWithDetails3BasedRestore.ps1 +++ b/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/WhereIsMyFileWithDetails3BasedRestore.ps1 @@ -1,78 +1,65 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$UserUpn -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ - $ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) - $ctx.Load($ctx.Web.Webs) - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -try -{ -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url " Items in the recycle bin: " $rb.Count.ToString() -} catch [Net.WebException] - { - - Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red - -} - -$myarray=@() -for($i=0;$i -lt $rb.Count ;$i++) -{ - - $ctx.Load($rb[$i].Author) - $ctx.Load($rb[$i].DeletedBy) - $ctx.ExecuteQuery() - $obj = $rb[$i] - $obj | Add-Member NoteProperty AuthorLoginName($rb[$i].Author.LoginName) - $obj | Add-Member NoteProperty DeletedByLoginName($rb[$i].DeletedBy.LoginName) - $myarray+=$obj - -} - -Write-Host "Items to process: " $myarray.Count - -for($i=0;$i -lt $myarray.Count ; $i++){ -if($myarray[$i].DeletedByLoginName -eq $UserUpn ) -{ -$myarray[$i].Restore() -try{ -$ctx.ExecuteQuery() -Write-Host $myarray[$i].LeafName " restored" -ForegroundColor Green -} -catch [Net.WebException] -{ - Write-Host $myarray[$i].LeafName " failed" $_.Message.ToString() -ForegroundColor Red -} -} -} - - - - - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $ctx.Load($ctx.Web.Webs) + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + + try{ + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url " Items in the recycle bin: " $rb.Count.ToString() + } + catch [Net.WebException] { + Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $myarray=@() + + for($i=0;$i -lt $rb.Count ;$i++){ + $ctx.Load($rb[$i].Author) + $ctx.Load($rb[$i].DeletedBy) + $ctx.ExecuteQuery() + $obj = $rb[$i] + $obj | Add-Member NoteProperty AuthorLoginName($rb[$i].Author.LoginName) + $obj | Add-Member NoteProperty DeletedByLoginName($rb[$i].DeletedBy.LoginName) + $myarray+=$obj + } + + Write-Host "Items to process: " $myarray.Count + + for($i=0;$i -lt $myarray.Count ; $i++){ + if($myarray[$i].DeletedByLoginName -eq $UserUpn ){ + $myarray[$i].Restore() + + try{ + $ctx.ExecuteQuery() + Write-Host $myarray[$i].LeafName " restored" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host $myarray[$i].LeafName " failed" $_.Message.ToString() -ForegroundColor Red + } + } + } } @@ -90,11 +77,8 @@ $userupn="i:0#.f|membership|uss2@arletka.cloudns.org" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -UserUpn $userupn - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site -UserUpn $userupn } diff --git a/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/description.md b/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/description.md index 4313daf1..9d4430d2 100644 --- a/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/description.md +++ b/Site Management/Recycle Bin/Restore all files, items, lists deleted by a single employee/description.md @@ -16,25 +16,19 @@ More variations on the script and more options are coming so click on View Contr -The script will notify you as it loops through the sites if there are any items at all in the site collection recycle bin; if it finds items DELETED BY the specified user, it will restore them and print out their names in green. +The script will notify you as it loops through the sites if there are any items at all in the site collection recycle bin; if it finds items DELETED BY the specified user, it will restore them and print out their names **in green**. -If it runs into any troubles (e.g. it cannot access the public site and the mysite host) it will notify you about it in red - - - - - - - - +If it runs into any troubles (e.g. it cannot access the public site and the mysite host) it will notify you about it **in red** + + Before running the script you need to open the file and enter the correct the data: -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -44,7 +38,7 @@ $Username="admin@tenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://tenant-admin.sharepoint.com" $userupn="i:0#.f|membership|uss2@arletka.cloudns.org" - + ``` $Username correponds to the global admin who has access to all the site collections you want to loop through. $userupn is the naughty employee's SharePoint loginname who deleted the items. Pay attention to the format and DO NOT remove i:0#.f|membership| part unless you are 100% sure that your SharePoint user loginname includes something else than this. diff --git a/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/RestoreAllRecycleBinItems.ps1 b/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/RestoreAllRecycleBinItems.ps1 index a8b65916..9ff2317d 100644 --- a/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/RestoreAllRecycleBinItems.ps1 +++ b/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/RestoreAllRecycleBinItems.ps1 @@ -1,70 +1,56 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - -try -{ -$ctx.ExecuteQuery() -} catch [Net.WebException] - { - - Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red -} - - $ctx.Load($ctx.Site) - $ctx.Load($ctx.Web.Webs) - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -try -{ -$ctx.ExecuteQuery() -Write-Host $ctx.Site.Url " Items in the recycle bin: " $rb.Count.ToString() -} catch [Net.WebException] - { - - Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red - -} - -$myarray=@() -for($i=0;$i -lt $rb.Count ;$i++) -{ - - $obj = $rb[$i] - $myarray+=$obj - -} - -Write-Host "Items to process: " $myarray.Count - -for($i=0;$i -lt $myarray.Count ; $i++){ - -$myarray[$i].Restore() -try{ -$ctx.ExecuteQuery() -Write-Host $myarray[$i].LeafName " restored" -ForegroundColor Green -} -catch [Net.WebException] -{ - Write-Host $myarray[$i].LeafName " failed" $_.Message.ToString() -ForegroundColor Red -} - -} - - - - - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + + try{ + $ctx.ExecuteQuery() + } + catch [Net.WebException] { + Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $ctx.Load($ctx.Site) + $ctx.Load($ctx.Web.Webs) + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + + try{ + $ctx.ExecuteQuery() + Write-Host $ctx.Site.Url " Items in the recycle bin: " $rb.Count.ToString() + } + catch [Net.WebException] { + Write-Host $ctx.Site.Url " failed" $_.Exception.Message.ToString() -ForegroundColor Red + } + + $myarray=@() + + for($i=0;$i -lt $rb.Count ;$i++){ + $obj = $rb[$i] + $myarray+=$obj + } + + Write-Host "Items to process: " $myarray.Count + + for($i=0;$i -lt $myarray.Count ; $i++){ + $myarray[$i].Restore() + + try{ + $ctx.ExecuteQuery() + Write-Host $myarray[$i].LeafName " restored" -ForegroundColor Green + } + catch [Net.WebException]{ + Write-Host $myarray[$i].LeafName " failed" $_.Message.ToString() -ForegroundColor Red + } + } } @@ -81,11 +67,8 @@ $AdminUrl="https://trial765-admin.sharepoint.com" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site } diff --git a/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/description.md b/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/description.md index ab43d2a6..168fcd3a 100644 --- a/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/description.md +++ b/Site Management/Recycle Bin/Restore all reycle bin items across all site collections/description.md @@ -1,32 +1,13 @@ The script loops across all site collections in the tenant and finds all deleted items and restores them all. - - -More variations of the script are available on Technet Gallery: https://gallery.technet.microsoft.com/office/site/search?query=recycle%20bin&f%5B1%5D.Value=recycle%20bin&f%5B1%5D.Type=SearchText&f%5B0%5D.Value=Arleta%20Wanat&f%5B0%5D.Type=User&ac=4 - - +More variations of the script are available on [Technet Gallery](https://gallery.technet.microsoft.com/office/site/search?query=recycle%20bin&f%5B1%5D.Value=recycle%20bin&f%5B1%5D.Type=SearchText&f%5B0%5D.Value=Arleta%20Wanat&f%5B0%5D.Type=User&ac=4) - +The script will notify you as it loops through the sites if there are any items at all in the site collection recycle bin; it will restore them and print out their names **in green**. - +If it runs into any troubles (e.g. duplicate items already exist and the mysite host) it will notify you about it **in red** -The script will notify you as it loops through the sites if there are any items at all in the site collection recycle bin; it will restore them and print out their names in green. - -If it runs into any troubles (e.g. duplicate items already exist and the mysite host) it will notify you about it in red - - - - - - - - - - - - - - + + Before running the script you need to open the file and enter the correct the data: diff --git a/Site Management/Recycle Bin/Restore one file from a Given Site/RestoreDeletedItem.ps1 b/Site Management/Recycle Bin/Restore one file from a Given Site/RestoreDeletedItem.ps1 index b7dd6ede..49eabd8a 100644 --- a/Site Management/Recycle Bin/Restore one file from a Given Site/RestoreDeletedItem.ps1 +++ b/Site Management/Recycle Bin/Restore one file from a Given Site/RestoreDeletedItem.ps1 @@ -1,38 +1,29 @@ -function Restore-DeletedItem -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Restore-DeletedItem{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [GUID]$ItemGuid -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $rb=$ctx.Site.RecycleBin -$ctx.Load($rb) -$ctx.ExecuteQuery() - -$rb.GetById($ItemGuid).Restore() - -$ctx.ExecuteQuery() - - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + $ctx.Load($ctx.Web) + $rb=$ctx.Site.RecycleBin + $ctx.Load($rb) + $ctx.ExecuteQuery() + $rb.GetById($ItemGuid).Restore() + $ctx.ExecuteQuery() } - - - # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" diff --git a/Site Management/Recycle Bin/Restore one file from a Given Site/description.md b/Site Management/Recycle Bin/Restore one file from a Given Site/description.md index 9be6a13a..36bdfb8c 100644 --- a/Site Management/Recycle Bin/Restore one file from a Given Site/description.md +++ b/Site Management/Recycle Bin/Restore one file from a Given Site/description.md @@ -1,22 +1,12 @@ -Powershell script that restores a single file deleted and present in the recycle bin of that site. If you want to restore all files or see a report on them first, please refer to Related Scripts section. +Powershell script that restores a single file deleted and present in the recycle bin of that site. If you want to restore all files or see a report on them first, please refer to **Related Scripts** section. - - -Works with group sites! +**Works with group sites!** - - - - -The script requires SharePoint Online SDK. After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: - -(usually if not, they will be under 16\ISAPI\) - - +The script requires [SharePoint Online SDK](https://www.microsoft.com/en-us/download/details.aspx?id=42038). After installing the SDK verify if the path to 2 libraries: Client.dll and Client.Runtime.dll are in the same location as below: - +(usually if not, they will be under **16**\ISAPI\) -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -25,20 +15,13 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="2190@sampletenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://sampletenant.sharepoint.com/sites/dgd" +``` Insert the credentials before running the script. - - - -Please share your thoughts in the Q&A section! +### Please share your thoughts in the Q&A section! +## Related scripts +[Create a report on deleted files within one site using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Create-a-report-on-deleted-496ce018) - - - - -Related scripts -Create a report on deleted files within one site using Powershell - -Restore All Files from a Given Site using Powershell +[Restore All Files from a Given Site using Powershell](https://gallery.technet.microsoft.com/scriptcenter/Restore-All-Files-from-a-bc3037ac) diff --git a/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/WhereIsMyFile.ps1 b/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/WhereIsMyFile.ps1 index 19ee085c..fc15178c 100644 --- a/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/WhereIsMyFile.ps1 +++ b/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/WhereIsMyFile.ps1 @@ -1,47 +1,40 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) - $rb=$ctx.Web.RecycleBin -$ctx.Load($rb) -$ctx.ExecuteQuery() -Write-Host $ctx.Web.Url $rb.Count.ToString() - -for($i=0;$i -lt $rb.Count ;$i++) -{ - $obj = $rb[$i] - - Write-Output $obj - - -} -#$ctx.Web.RecycleBin.RestoreAll() -$ctx.ExecuteQuery() - - - -if($ctx.Web.Webs.Count -gt 0) - { - Write-Host "--"-ForegroundColor DarkGreen - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ctx.Web.Webs[$i].Url - } - } - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $rb=$ctx.Web.RecycleBin + $ctx.Load($rb) + $ctx.ExecuteQuery() + Write-Host $ctx.Web.Url $rb.Count.ToString() + + for($i=0;$i -lt $rb.Count ;$i++){ + $obj = $rb[$i] + + Write-Output $obj + } + + #$ctx.Web.RecycleBin.RestoreAll() + $ctx.ExecuteQuery() + + if($ctx.Web.Webs.Count -gt 0){ + Write-Host "--"-ForegroundColor DarkGreen + + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ctx.Web.Webs[$i].Url + } + } } @@ -58,11 +51,8 @@ $AdminUrl="https://tenant-admin.sharepoint.com" Connect-SPOService -Url $adminUrl $sites=(Get-SPOSite).Url -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site } diff --git a/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/description.md b/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/description.md index 6eb121c9..3df93821 100644 --- a/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/description.md +++ b/Site Management/Recycle Bin/Retrieve all reycle bin items across all site collections/description.md @@ -1,28 +1,18 @@ The script loops through all site collections, their subsites and retrieves all items from the recycle bin. The items can be seen in the console window or you can create an Excel report -* doesn't apply to group site collections or personal sites +* doesn't apply to group site collections or personal sites The script loops through all site collections, their subsites and retrieves all items from the recycle bin. The items can be seen in the console window - - - - - + or you can create an Excel report using | Export-csv - C:\Users\ivo\Desktop\wiki\technet\whereismyfile.ps1 | export-csv c:\users\ivo\desktop\whereismyfile.csv - - - + ```C:\Users\ivo\Desktop\wiki\technet\whereismyfile.ps1 | export-csv c:\users\ivo\desktop\whereismyfile.csv``` - - - - + The script requires SharePoint Online Management Shell and SharePoint Online SDK: @@ -32,11 +22,9 @@ http://www.microsoft.com/en-us/download/details.aspx?id=30722 - - Before running the script enter correct paths to the SDK and your tenant data: -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -45,10 +33,10 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="user@tenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://tenant-admin.sharepoint.com" - +``` -Let me know about your experience in the Q&A section! +### Let me know about your experience in the Q&A section! diff --git a/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/WithUnifiedGroups.ps1 b/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/WithUnifiedGroups.ps1 index 17253212..72cd36b3 100644 --- a/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/WithUnifiedGroups.ps1 +++ b/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/WithUnifiedGroups.ps1 @@ -1,47 +1,40 @@ -function Get-DeletedItems -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Get-DeletedItems{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url -) -#$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.Webs) - $rb=$ctx.Web.RecycleBin -$ctx.Load($rb) -$ctx.ExecuteQuery() -Write-Host $ctx.Web.Url $rb.Count.ToString() - -for($i=0;$i -lt $rb.Count ;$i++) -{ - $obj = $rb[$i] - - Write-Output $obj - - -} -#$ctx.Web.RecycleBin.RestoreAll() -$ctx.ExecuteQuery() - - - -if($ctx.Web.Webs.Count -gt 0) - { - Write-Host "--"-ForegroundColor DarkGreen - for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++) - { - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ctx.Web.Webs[$i].Url - } - } - + ) + #$password = ConvertTo-SecureString -string $AdminPassword -AsPlainText -Force + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.Webs) + $rb=$ctx.Web.RecycleBin + $ctx.Load($rb) + $ctx.ExecuteQuery() + Write-Host $ctx.Web.Url $rb.Count.ToString() + + for($i=0;$i -lt $rb.Count ;$i++){ + $obj = $rb[$i] + + Write-Output $obj + } + + #$ctx.Web.RecycleBin.RestoreAll() + $ctx.ExecuteQuery() + + if($ctx.Web.Webs.Count -gt 0){ + Write-Host "--"-ForegroundColor DarkGreen + + for($i=0;$i -lt $ctx.Web.Webs.Count ;$i++){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ctx.Web.Webs[$i].Url + } + } } @@ -66,16 +59,10 @@ Import-PSSession $sesja $unifiedGroups=(get-unifiedGroup).SharePointSiteUrl -foreach($site in $sites) -{ - - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site - +foreach($site in $sites){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $site } - - -foreach($ug in $unifiedGroups) -{ - Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ug -} \ No newline at end of file +foreach($ug in $unifiedGroups){ + Get-DeletedItems -Username $Username -AdminPassword $AdminPassword -Url $ug +} diff --git a/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/description.md b/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/description.md index d435aafd..baacdbc3 100644 --- a/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/description.md +++ b/Site Management/Recycle Bin/Retrieve all reycle bin items across all sites incl group sites/description.md @@ -1,26 +1,14 @@ -* including the group sites - - +* including the group sites The script loops through all site collections, their subsites and retrieves all items from the recycle bin. The items can be seen in the console window - - - - - + or you can create an Excel report using | Export-csv - C:\Users\ivo\Desktop\wiki\technet\whereismyfile.ps1 | export-csv c:\users\ivo\desktop\whereismyfile.csv - - - - +``` C:\Users\ivo\Desktop\wiki\technet\whereismyfile.ps1 | export-csv c:\users\ivo\desktop\whereismyfile.csv``` - - - + The script requires SharePoint Online Management Shell and SharePoint Online SDK: @@ -28,10 +16,6 @@ http://technet.microsoft.com/en-us/library/fp161372(v=office.15).aspx http://www.microsoft.com/en-us/download/details.aspx?id=30722 - - - - Before running the script enter correct paths to the SDK and your tenant data: ```PowerShell diff --git a/Site Management/Remove SPO subsite/Remove SPO subsite.ps1 b/Site Management/Remove SPO subsite/Remove SPO subsite.ps1 index 53869cc4..8c067f4d 100644 --- a/Site Management/Remove SPO subsite/Remove SPO subsite.ps1 +++ b/Site Management/Remove SPO subsite/Remove SPO subsite.ps1 @@ -9,38 +9,30 @@ function GetAllSubsitesAndDelete($SiteUrl) $ctx2.Load($sites2) $ctx2.ExecuteQuery() - if($sites2.Count -gt 0) - { - for($i=0;$i -lt $sites2.Count ;$i++) - { + if($sites2.Count -gt 0) { + for($i=0;$i -lt $sites2.Count ;$i++) { GetAllSubsitesAndDelete($sites2[$i].Url) } - try - { - $rootWeb2.DeleteObject() + try { + $rootWeb2.DeleteObject() $ctx2.ExecuteQuery() Write-Host "Subsite " $rootWeb2.Url " has been removed" } - catch [Net.WebException] - { + catch [Net.WebException] { Write-Host $_.Exception.ToString() } - } - else - { - try - { + } + else { + try { $rootWeb2.DeleteObject() $ctx2.ExecuteQuery() Write-Host "Subsite " $rootWeb2.Url " has been removed" } - catch [Net.WebException] - { + catch [Net.WebException] { Write-Host $_.Exception.ToString() } - } - + } } #paths to SDK (copied from Victor's comment) diff --git a/Site Management/Set RequestAccessEmail for all subsites in one site collection/RequestEmailAddress.ps1 b/Site Management/Set RequestAccessEmail for all subsites in one site collection/RequestEmailAddress.ps1 index 12641efc..4c960948 100644 --- a/Site Management/Set RequestAccessEmail for all subsites in one site collection/RequestEmailAddress.ps1 +++ b/Site Management/Set RequestAccessEmail for all subsites in one site collection/RequestEmailAddress.ps1 @@ -1,46 +1,37 @@ Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll" -function Set-SPOWebRequestAccessEmail -{ -param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOWebRequestAccessEmail{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] $password, [Parameter(Mandatory=$true,Position=4)] [string]$RequestAccessEmail - ) - - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) - $ctx.Load($ctx.Web) - $ctx.ExecuteQuery() - Write-Host "Changing for " $ctx.Web.Url - $ctx.Web.RequestAccessEmail=$RequestAccessEmail - $ctx.Web.Update() - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web.Webs) - $ctx.ExecuteQuery() - - if($ctx.Web.Webs.Count -ne 0) - { - foreach($webbie in $ctx.Web.Webs) - { - - - Set-SPOWebRequestAccessEmail -Username $Username -Url $webbie.Url -password $password -RequestAccessEmail $RequestAccessEmail - - - } - - } - - } + ) + + + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password) + $ctx.Load($ctx.Web) + $ctx.ExecuteQuery() + Write-Host "Changing for " $ctx.Web.Url + $ctx.Web.RequestAccessEmail=$RequestAccessEmail + $ctx.Web.Update() + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web.Webs) + $ctx.ExecuteQuery() + + if($ctx.Web.Webs.Count -ne 0){ + foreach($webbie in $ctx.Web.Webs){ + Set-SPOWebRequestAccessEmail -Username $Username -Url $webbie.Url -password $password -RequestAccessEmail $RequestAccessEmail + } + } +} # Paths to SDK. Please verify location on your computer. diff --git a/Site Management/Set RequestAccessEmail for all subsites in one site collection/description.md b/Site Management/Set RequestAccessEmail for all subsites in one site collection/description.md index b28cc009..1a303fb8 100644 --- a/Site Management/Set RequestAccessEmail for all subsites in one site collection/description.md +++ b/Site Management/Set RequestAccessEmail for all subsites in one site collection/description.md @@ -1,12 +1,8 @@ Powershell script to set the email for access requests. The setting is available from SharePoint Online User Interface at: -Site Settings>Site Permissions>Access Requests Settings +**Site Settings** > **Site Permissions** > **Access Requests Settings** - - - - - + The script requires the following libraries. Please confirm that the files are in the same location on your PC. diff --git a/Site Management/Set theme of your SharePoint Online site/Theme.ps1 b/Site Management/Set theme of your SharePoint Online site/Theme.ps1 index 42075fa2..8f68d755 100644 --- a/Site Management/Set theme of your SharePoint Online site/Theme.ps1 +++ b/Site Management/Set theme of your SharePoint Online site/Theme.ps1 @@ -1,35 +1,32 @@ -function Set-SPOTheme -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOTheme{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, -[Parameter(Mandatory=$true,Position=4)] + [Parameter(Mandatory=$true,Position=4)] [string]$palette, -[Parameter(Mandatory=$true,Position=5)] + [Parameter(Mandatory=$true,Position=5)] [string]$font - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() + ) - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.ThemeInfo) - $ctx.ExecuteQuery() - $palette=$ctx.web.ServerRelativeUrl+$palette - $font=$ctx.Web.ServerRelativeUrl+$font - $mynu=Out-Null - Write-Host "Current theme " $ctx.Web.ThemeInfo.AccessibleDescription - Write-Host $ctx.Web.ThemeInfo.ThemeBackgroundImageUri -$ctx.Web.ApplyTheme($palette,$font,$mynu, $true) -$ctx.ExecuteQuery() - - } + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.ThemeInfo) + $ctx.ExecuteQuery() + $palette=$ctx.web.ServerRelativeUrl+$palette + $font=$ctx.Web.ServerRelativeUrl+$font + $mynu=Out-Null + Write-Host "Current theme " $ctx.Web.ThemeInfo.AccessibleDescription + Write-Host $ctx.Web.ThemeInfo.ThemeBackgroundImageUri + $ctx.Web.ApplyTheme($palette,$font,$mynu, $true) + $ctx.ExecuteQuery() +} diff --git a/Site Management/Set theme of your SharePoint Online site/description.md b/Site Management/Set theme of your SharePoint Online site/description.md index 8952118c..3b89366d 100644 --- a/Site Management/Set theme of your SharePoint Online site/description.md +++ b/Site Management/Set theme of your SharePoint Online site/description.md @@ -1,28 +1,18 @@ Powershell script to set theme for your site. - - The script chooses one of the default font and color palettes available from Designer Gallery: - - - + The font and colors are applied to existing site. The current settings (they can be modified) change the look of the page into: - - - - - - -1. Install SharePoint Online SDK. + -2. Open the script (e.g. in Notepad) and enter your data in the following lines: +**1.** Install SharePoint Online SDK. - +**2.** Open the script (e.g. in Notepad) and enter your data in the following lines: -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" @@ -31,19 +21,14 @@ Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extens $Username="admin@tenant.onmicrosoft.com" $AdminPassword=Read-Host -Prompt "Password" -AsSecureString $AdminUrl="https://tenant.sharepoint.com/sites/powie1" + ``` - - a) Find paths to SDK libraries SharePoint.Client.Runtime.dll and SharePoint.Client.dll on your local computer and replace the ones in the file (they may be very similar or exactly the same!) b) Insert the username and the url of the site where you want to change the theme. You will be prmopted for the password during the script execution so do not enter it here. - - -3. Run the script in any Powershell Module. +**3.** Run the script in any Powershell Module. -4. Verify the results on the site. - - +**4.** Verify the results on the site. -If you have any questions, do not hesitate to post them in the Q&A section! +#### If you have any questions, do not hesitate to post them in the Q&A section! diff --git a/Site Management/Update locale id for all personal sites/LocaleID.ps1 b/Site Management/Update locale id for all personal sites/LocaleID.ps1 index 6de5c803..e177f7e5 100644 --- a/Site Management/Update locale id for all personal sites/LocaleID.ps1 +++ b/Site Management/Update locale id for all personal sites/LocaleID.ps1 @@ -1,63 +1,57 @@  # Vadim Gremyachev's function - Function Invoke-LoadMethod() { -param( - [Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"), - [string]$PropertyName -) - $ctx = $Object.Context - $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load") - $type = $Object.GetType() - $clientLoad = $load.MakeGenericMethod($type) - - - $Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name) - $Expression = [System.Linq.Expressions.Expression]::Lambda( - [System.Linq.Expressions.Expression]::Convert( - [System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName), - [System.Object] - ), - $($Parameter) - ) - $ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1) - $ExpressionArray.SetValue($Expression, 0) - $clientLoad.Invoke($ctx,@($Object,$ExpressionArray)) +Function Invoke-LoadMethod() { + param( + [Microsoft.SharePoint.Client.ClientObject]$Object = $(throw "Please provide a Client Object"), + [string]$PropertyName + ) + + $ctx = $Object.Context + $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load") + $type = $Object.GetType() + $clientLoad = $load.MakeGenericMethod($type) + + $Parameter = [System.Linq.Expressions.Expression]::Parameter(($type), $type.Name) + $Expression = [System.Linq.Expressions.Expression]::Lambda( + [System.Linq.Expressions.Expression]::Convert( + [System.Linq.Expressions.Expression]::PropertyOrField($Parameter,$PropertyName), + [System.Object] + ), + $($Parameter) + ) + + $ExpressionArray = [System.Array]::CreateInstance($Expression.GetType(), 1) + $ExpressionArray.SetValue($Expression, 0) + $clientLoad.Invoke($ctx,@($Object,$ExpressionArray)) } -function Set-SPOUserRegionalSettings -{ - - param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOUserRegionalSettings{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$LocaleID - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - - $ctx.Load($ctx.Web.RegionalSettings.TimeZones) - Invoke-LoadMethod -Object $ctx.Web.RegionalSettings -PropertyName "LocaleID" - $ctx.ExecuteQuery() + ) - Write-Host "Old locale id: " $ctx.Web.RegionalSettings.LocaleId.ToString() + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() - $ctx.Web.RegionalSettings.LocaleId=$LocaleID -$ctx.Web.Update() -$ctx.ExecuteQuery() + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.RegionalSettings.TimeZones) + Invoke-LoadMethod -Object $ctx.Web.RegionalSettings -PropertyName "LocaleID" + $ctx.ExecuteQuery() - } - - + Write-Host "Old locale id: " $ctx.Web.RegionalSettings.LocaleId.ToString() + $ctx.Web.RegionalSettings.LocaleId=$LocaleID + $ctx.Web.Update() + $ctx.ExecuteQuery() +} # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll" @@ -72,19 +66,16 @@ $LocaleID=1033 $users=get-SPOUser -Site $myhost -foreach($user in $users) -{ - - if($user.LoginName.Contains('@')) - { - $persweb=$user.LoginName.Replace(".","_").Replace("@","_") - $persweb=$myhost+"/personal/"+$persweb - Write-Host $persweb +foreach($user in $users){ + if($user.LoginName.Contains('@')){ + $persweb=$user.LoginName.Replace(".","_").Replace("@","_") + $persweb=$myhost+"/personal/"+$persweb + Write-Host $persweb - $AdminUrl=$persweb + $AdminUrl=$persweb - Set-SPOUserRegionalSettings -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -LocaleID $LocaleID - } + Set-SPOUserRegionalSettings -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -LocaleID $LocaleID + } } diff --git a/Site Management/Update locale id for all personal sites/description.md b/Site Management/Update locale id for all personal sites/description.md index 04612d55..fd1a5a35 100644 --- a/Site Management/Update locale id for all personal sites/description.md +++ b/Site Management/Update locale id for all personal sites/description.md @@ -1,34 +1,21 @@ -Acknowledegement -The script uses Vadim Gremyachev's Invoke-LoadMethod published here +### Acknowledegement - +The script uses [Vadim Gremyachev's](https://sharepoint.stackexchange.com/users/10610/vadim-gremyachev) Invoke-LoadMethod published [here](https://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell) - +### Description -Description The script updates locale id in regional settings of all personal sites to which you have access. The locale id can later be verified by going to Site Settings>Regional Settings. - - The script requires the following libraries: - - -PowerShell +```PowerShell # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll" - - - - - - + ``` Enter the correct data and specify the locale id you'd like to set: - - ```PowerShell # Insert the credentials and the name of the admin site $Username="admin@tenant.onmicrosoft.com" @@ -37,19 +24,11 @@ Connect-SPOService https://tenant-admin.sharepoint.com -Credential $Username $myhost="https://tenant-my.sharepoint.com" $LocaleID=1033 ``` - - - - - If you are not currently an Administrator of the user's personal site, you can gain access using: - - ```PowerShell Set-SPOUser -Site $urelek -LoginName $username -IsSiteCollectionAdmin $true ``` - In order to use the cmdlet, you can either modify the.ps1 file or write a separate script. diff --git a/Site Management/Update the time zones in all personal sites/PersonalRegSettings.ps1 b/Site Management/Update the time zones in all personal sites/PersonalRegSettings.ps1 index d8a3c125..0cee28b0 100644 --- a/Site Management/Update the time zones in all personal sites/PersonalRegSettings.ps1 +++ b/Site Management/Update the time zones in all personal sites/PersonalRegSettings.ps1 @@ -1,33 +1,29 @@ -function Set-SPOUserRegionalSettings -{ - param ( - [Parameter(Mandatory=$true,Position=1)] +function Set-SPOUserRegionalSettings{ + param ( + [Parameter(Mandatory=$true,Position=1)] [string]$Username, - [Parameter(Mandatory=$true,Position=2)] + [Parameter(Mandatory=$true,Position=2)] $AdminPassword, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$Url, - [Parameter(Mandatory=$true,Position=3)] + [Parameter(Mandatory=$true,Position=3)] [string]$TimeZoneID - ) - - $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) - $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) - $ctx.ExecuteQuery() - - $ctx.Load($ctx.Web) - $ctx.Load($ctx.Web.RegionalSettings.TimeZone) - $ctx.Load($ctx.Web.RegionalSettings.TimeZones) - $ctx.ExecuteQuery() - - - $ctx.Web.RegionalSettings.TimeZone=$ctx.Web.RegionalSettings.TimeZones.GetbyID($TimeZoneID) - $ctx.Web.Update() - $ctx.ExecuteQuery() + ) + $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url) + $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword) + $ctx.ExecuteQuery() + + $ctx.Load($ctx.Web) + $ctx.Load($ctx.Web.RegionalSettings.TimeZone) + $ctx.Load($ctx.Web.RegionalSettings.TimeZones) + $ctx.ExecuteQuery() + + $ctx.Web.RegionalSettings.TimeZone=$ctx.Web.RegionalSettings.TimeZones.GetbyID($TimeZoneID) + $ctx.Web.Update() + $ctx.ExecuteQuery() } - # Paths to SDK. Please verify location on your computer. Add-Type -Path "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.dll" Add-Type -Path "c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Client.Runtime\v4.0_16.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.Client.Runtime.dll" @@ -40,17 +36,15 @@ $myhost="https://t321-my.sharepoint.com" $users=get-SPOUser -Site $myhost $TimeZoneID=63 -foreach($user in $users) -{ - if($user.LoginName.Contains('@')) - { - $persweb=$user.LoginName.Replace(".","_").Replace("@","_") - $persweb=$myhost+"/personal/"+$persweb - Write-Host $persweb +foreach($user in $users){ + if($user.LoginName.Contains('@')){ + $persweb=$user.LoginName.Replace(".","_").Replace("@","_") + $persweb=$myhost+"/personal/"+$persweb + Write-Host $persweb - $AdminUrl=$persweb + $AdminUrl=$persweb - Set-SPoUserRegionalSettings -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -TimeZoneID $TimeZoneID - } + Set-SPoUserRegionalSettings -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -TimeZoneID $TimeZoneID + } }