Skip to content

Instantly share code, notes, and snippets.

@arjancornelissen
Last active October 6, 2018 15:40
Show Gist options
  • Save arjancornelissen/5db3971dcafa95050110fd6e0de633c7 to your computer and use it in GitHub Desktop.
Save arjancornelissen/5db3971dcafa95050110fd6e0de633c7 to your computer and use it in GitHub Desktop.
Script to force the renewal of Content Types
param
(
# give the URL of the site or when to reset for every site the admin url
[Parameter(Mandatory=$true)]
[string]$url,
# Do we need to use the weblogin
[Parameter(Mandatory=$false)]
[switch]
$useweblogin
)
Function RemoveAllTimeStamps([Microsoft.SharePoint.Client.Web] $web)
{
if ($web.AllProperties.FieldValues.ContainsKey("MetadataTimeStamp"))
{
$web.AllProperties.FieldValues["MetadataTimeStamp"] = [string]::Empty
$web.AllProperties.FieldValues.Update()
}
}
$orgTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "Set Renewal for content types"
if($useweblogin) { Connect-PnPOnline -Url $url -UseWebLogin } else { Connect-PnPOnline -Url $url }
if($url.Contains("-admin.sharepoint.com"))
{
$sites = Get-PnPTenantSite
$total = $sites.Count
$counter = 0
$sites | % {
if($useweblogin) { Connect-PnPOnline -Url $_.Url -UseWebLogin } else { Connect-PnPOnline -Url $_.Url }
$Host.UI.RawUI.WindowTitle = "Set Renewal for content types $counter / $total"
RemoveAllTimeStamps (Get-PnPWeb -Includes AllProperties)
$counter++
Disconnect-PnPOnline
}
}
else
{
#Just do this site collection
RemoveAllTimeStamps (Get-PnPWeb -Includes AllProperties)
}
Disconnect-PnPOnline
$Host.UI.RawUI.WindowTitle = $orgTitle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment