Last active
November 10, 2022 20:39
-
-
Save peplau/ad9ff6daea9593ae376a70789be478a1 to your computer and use it in GitHub Desktop.
SPE: Advanced Quick Download Tree as Package - Allows the user to pick and choose among Linked Items to include in the package as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Function -Name Setup-PackageGenerator | |
function Get-UniqueLinks { | |
param( | |
[item]$Item | |
) | |
$combined = @() | |
$combined += Get-UniqueReferrers $Item | |
$combined += Get-UniqueReferences $Item | |
return $combined | Sort-Object -Property @{Expression={$_.ID}} -Unique | |
} | |
function Get-UniqueReferrers { | |
param( | |
[item]$Item | |
) | |
$items = Get-ItemReferrer -Item $Item | |
return $items | Sort-Object -Property @{Expression={$_.ID}} -Unique | |
} | |
function Get-UniqueReferences { | |
param( | |
[item]$Item | |
) | |
$links = $Item.Links.GetAllLinks($true,$true) | |
$items = @() | |
foreach ($link in $links) { | |
$path = $link.TargetDatabaseName | |
$path += ":" + $link.TargetPath | |
try { | |
$item = Get-Item -Database $link.TargetDatabaseName -Path $path -ErrorAction SilentlyContinue | |
if ($item -ne $null){ | |
$items += $item | |
} | |
} | |
catch {} | |
} | |
return $items | Sort-Object -Property @{Expression={$_.ID}} -Unique | |
} | |
function Get-OptionsForItems { | |
param( | |
[item[]]$Items, | |
[Item]$baseItem | |
) | |
$options = [ordered]@{} | |
foreach ($item in $Items) { | |
$display = $item.Paths.Path.ToString() | |
if ($baseItem.Database.Name -ne $item.Database.Name){ | |
$display = $item.Database.Name + ":" + $display | |
} | |
if ($options.Contains($display) -eq $false){ | |
$options.Add($display, $item.ID.ToString()) | |
} | |
} | |
return $options | |
} | |
function Filter-ByPathContains { | |
param( | |
[item[]]$Items, | |
[string]$path | |
) | |
$filtered = @() | |
$filtered += $Items | Where-Object -FilterScript { $_.Paths.Path -like $path } | |
return $filtered | |
} | |
function Get-OtherItems { | |
param( | |
[item[]]$coveredItems, | |
[item[]]$allItems | |
) | |
$others = @() | |
foreach ($i in $allItems) { | |
$filtered = $coveredItems | Where-Object -FilterScript { $_.ID -eq $i.ID } | |
if ($filtered -eq $null -or $filtered.Count -eq 0){ | |
$others += $i | |
} | |
} | |
return $others | |
} | |
function Get-ChildrenToInclude { | |
param( | |
[Item]$baseItem, | |
[string]$rootOption | |
) | |
$items = @() | |
if($rootOption -eq "RootAndDescendants"){ | |
$items += $baseItem | |
$items += $baseItem.Axes.GetDescendants() | |
} | |
elseif($rootOption -eq "RootAndChildren"){ | |
$items += $baseItem | |
$items += $baseItem.Children | |
} | |
elseif($rootOption -eq "DescendantsOnly"){ | |
$items += $baseItem.Axes.GetDescendants() | |
} | |
elseif($rootOption -eq "ChildrenOnly"){ | |
$items += $baseItem.Children | |
} | |
return $items | |
} | |
$linkOptions = [ordered]@{ | |
"Do not include linked items" = 0 | |
"Include parent links only" = 1 | |
"Include all linked items" = 2 | |
} | |
$linkOptionsTooltips = [ordered]@{ | |
0 = "Linked items are not included in the package" | |
1 = "Only items linked to the parent will be included in the package" | |
2 = "All linked items will be included in the package" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Line 1 - Changed the Import-Function Name to Setup-PackageGeneratorAdvanced | |
Line 5 - Removed as the $path variable was not used | |
Lines 20-22 - Updated to always show the Links tab, which is now a radiobox | |
Line 74 - Replaced by the block from lines 75 to 149 | |
Lines 76 to 87 - Replaced by the block from lines 151 to 162 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool. I'll give it a try.