如何与PowerShell找到所有汇合页

发布于 2025-01-26 16:55:38 字数 1351 浏览 3 评论 0 原文

我正在尝试在我的实例中拉动所有 Confluence页面,这些页面从1/1/21开始就没有修改。自1/1/21以来,我能够获得所有未经修改的父页面,很容易。但是,我现在试图获取所有 child 页面。

我知道 get-confluencechildPage 具有 -recurse 选项()但是,当我使用它时,我会得到 Invoke-method:目前仅支持Direct Children

我创建了一个脚本,该脚本将在顶级页面上迭代并检查是否有子页面。我不知道如何设置DO,直到不复制子页面输出,请参见下图。

这是我到目前为止所拥有的。一旦我可以弄清楚 get-confluencechildpage 弄清楚,我就可以添加一个if并基于日期修改。有人可以将我指向正确的方向吗?请谢谢你。

$Pages = get-confluencespace -spacekey 'SPACEKEY' | get-confluencepage
$NotMod = $pages | ? { $_.version.when -lt (get-date 1/1/21) }
$full = @()
foreach ($1 in $notmod) {
    $full += get-confluencepage $1.id
    if ($1 | Get-ConfluenceChildPage) {
        $Descendents = $1 | Get-ConfluenceChildPage
        foreach ($child in $Descendents) {
            $full += $child
            do {
                $Next = 1
                $Next = $child | Get-ConfluenceChildPage
                if ($next) {
                    $full += $next
                }
            } until (
                $null -eq $Next
            )
        }
    }
}

I'm trying to pull all Confluence pages in my instance that haven't been modified since 1/1/21. I was able to get all of the parent pages that haven't been modified since 1/1/21 fairly easily. However, I'm now trying to get all of the child pages.

I know get-confluencechildpage has a -recurse option (source) but when I use it I get Invoke-Method : Page children is currently only supported for direct children.

I've created a script that will iterate through the top level pages and check if there are child pages. What I can't figure out is how to setup the do until and not duplicate the child page output, see picture below.

Here's what I have so far. Once I can get the get-confluencechildpage figured out I can then add an if and base it on date modified. Can anybody point me in the right direction? Please and thank you.

$Pages = get-confluencespace -spacekey 'SPACEKEY' | get-confluencepage
$NotMod = $pages | ? { $_.version.when -lt (get-date 1/1/21) }
$full = @()
foreach ($1 in $notmod) {
    $full += get-confluencepage $1.id
    if ($1 | Get-ConfluenceChildPage) {
        $Descendents = $1 | Get-ConfluenceChildPage
        foreach ($child in $Descendents) {
            $full += $child
            do {
                $Next = 1
                $Next = $child | Get-ConfluenceChildPage
                if ($next) {
                    $full += $next
                }
            } until (
                $null -eq $Next
            )
        }
    }
}

Output of script

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾兮 2025-02-02 16:55:38

我刚刚测试了Atlassian的 confluenceps 模块(v2.5.1)在自托管汇合实例(v7.3.5)上,并且出现 get-confluencePage cmdlet 出现返回给定空间的整个文档树的扁平列表。

基于此,您的代码仅仅是:

# get all pages from a Confluence "Space"
$all_pages = Get-ConfluencePage -SpaceKey "myspacekey";

# filter all the pages to just get those last edited before a specified date
$timestamp = (get-date -Year 2021 -Month 1 -Day 1).Date;
$filtered  = $pages | where-object { $_.Version.When -lt $timestamp };

$filtered | format-table "Id"

   ID
   --
17714
67261
..etc

update

如果出于任何原因,您都不会从 get-confluencePage返回的空间中获得所有页面,则可以做a depth-first search 在树上使用使用 get get get fee -confluencechildpage

# get root pages in the space
$rootPages = ...

# push root pages onto a stack
$stack = new-object System.Collections.ArrayList;
foreach( $rootPage in $rootPages )
{
    $null = $stack.Add($rootPage);
}

# initialise the result set
$all_pages = new-object System.Collections.ArrayList;

# while stack not empty
while( $stack.Count -gt 0 )
{

    # pop the top page off the stack
    $parent = $stack[$stack.Count - 1];
    $stack.RemoveAt($stack.Count - 1);

    # add the top page to the result set
    $null = $all_pages.Add($parent);

    # get child pages
    write-host "getting child pages for '$($parent.Title)' ($($parent.ID))";
    $children = Get-ConfluenceChildPage -PageId $parent.ID;
    write-host ($children | format-table | out-string);

    # push child pages onto the stack
    foreach( $child in $children )
    {
        $null = $stack.Add($child);
    }

}

I've just tested Atlassian's ConfluencePS module (v2.5.1) on a self-hosted Confluence instance (v7.3.5), and the Get-ConfluencePage cmdlet appears to return a flattened list of the entire document tree for a given space.

Based on that, your code would simply be:

# get all pages from a Confluence "Space"
$all_pages = Get-ConfluencePage -SpaceKey "myspacekey";

# filter all the pages to just get those last edited before a specified date
$timestamp = (get-date -Year 2021 -Month 1 -Day 1).Date;
$filtered  = $pages | where-object { $_.Version.When -lt $timestamp };

$filtered | format-table "Id"

   ID
   --
17714
67261
..etc

Update

If, for whatever reason, you don't get all the pages in the Space returned from Get-ConfluencePage, you could do a depth-first search of the root pages in the tree using Get-ConfluenceChildPage:

# get root pages in the space
$rootPages = ...

# push root pages onto a stack
$stack = new-object System.Collections.ArrayList;
foreach( $rootPage in $rootPages )
{
    $null = $stack.Add($rootPage);
}

# initialise the result set
$all_pages = new-object System.Collections.ArrayList;

# while stack not empty
while( $stack.Count -gt 0 )
{

    # pop the top page off the stack
    $parent = $stack[$stack.Count - 1];
    $stack.RemoveAt($stack.Count - 1);

    # add the top page to the result set
    $null = $all_pages.Add($parent);

    # get child pages
    write-host "getting child pages for '$($parent.Title)' ($($parent.ID))";
    $children = Get-ConfluenceChildPage -PageId $parent.ID;
    write-host ($children | format-table | out-string);

    # push child pages onto the stack
    foreach( $child in $children )
    {
        $null = $stack.Add($child);
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文