Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Last active April 19, 2021 23:41
Show Gist options
  • Select an option

  • Save joshooaj/e4588308fd346169a709cf12a1f38ed2 to your computer and use it in GitHub Desktop.

Select an option

Save joshooaj/e4588308fd346169a709cf12a1f38ed2 to your computer and use it in GitHub Desktop.
Copy all view groups and their contents from child sites up to the parent site
#Requires -Modules MilestonePSTools, MilestonePSTools.ViewGroups
<#
This sample shows how you could copy all view groups defined in child sites within a Milestone Federated Hierarchy up to the parent
site. This way local users can login to their child-site directly, and create/use views defined there, and users logging in to the
parent site can get a copy of those same views.
With only a little more effort, this could be setup as a scheduled task to run daily to keep views at the parent site in sync with
the child sites.
Note: The term 'Master' will be replaced in the next version of MilestonePSTools to be pushed to PSGallery.
#>
Select-Site -MasterSite
$mainSite = Get-Site
foreach ($site in Get-Site -ListAvailable) {
if ($site.FQID.ObjectId -eq $mainSite.FQID.ObjectId) {
continue
}
# Collect all viewgroup definitions from child site
$site | Select-Site
$viewGroups = @{}
foreach ($viewGroup in Get-ViewGroup) {
if ($viewGroups.ContainsKey($viewGroup.Name)) {
Write-Warning "Skipping duplicate View Group '$($viewGroup.Name)' on site $($site.Name)."
continue
}
$viewGroups.$($viewGroup.Name) = $viewGroup | Get-ViewGroupXml
}
# Push viewgroup definitions to parent site
Select-Site -MasterSite
foreach ($viewGroupName in $viewGroups.Keys) {
$viewGroup = Get-ViewGroup -Name $viewGroupName -ErrorAction SilentlyContinue
if ($null -eq $viewGroup) {
$viewGroup = Add-ViewGroup -Name $viewGroupName
}
$viewGroup | Set-ViewGroupXml -Xml $viewGroups.$viewGroupName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment