更新SharePoint页面标题的作者,使用Power Automate。

huangapple go评论91阅读模式
英文:

Update Sharepoint Page Header Author using Power Automate

问题

我想要更新我们SharePoint公司内部新闻文章的页面标题作者。我决定尝试使用Power Automate来实现这一目标。

更新SharePoint页面标题的作者,使用Power Automate。

看起来这似乎不在页面的属性中,而是在页面内容本身。

是否有办法使用Power Automate实现这个目标?

英文:

I would like to update the Page Header Author of our SharePoint intranet news posts. I decided to try using Power Automate to achieve this.

更新SharePoint页面标题的作者,使用Power Automate。

It seems like this isn't in the properties of the page, but rather in the page content itself.

Is there any way this can be achieved using Power Automate?

答案1

得分: 0

您可以使用PnP PowerShell来设置SharePoint页面的作者信息。以下是用于相同操作的示例PnP PowerShell脚本:

Param(
    [Parameter(mandatory = $true)]
    [string]$SiteUrl,
    [Parameter(mandatory = $true)]
    [string]$PageName,
    [Parameter(mandatory = $true)]
    [string]$UserEmail
)

function Set-PageAuthorByline {

    # 连接到网站
    Connect-PnPOnline -Url $SiteUrl;

    # 如果连接中出现错误,则返回
    if ($null -eq $(Get-PnPConnection).ConnectionType) {
        return;
    }

    # 从指定的页面名称/URL获取页面对象
    $page = Get-PnPPage -Identity $PageName;

    # 如果找不到页面,则返回
    if ($null -eq $page) {
        Write-Error "页面名称无效";
        return;
    }

    # 从用户信息列表中获取所需的用户
    Write-Host "从用户信息列表获取用户信息..." -ForegroundColor Yellow;
    $user = Get-PnPUser | Where-Object Email -eq $UserEmail;

    if ($null -ne $user) {
        Write-Host "从用户信息列表获取用户信息。" -ForegroundColor Yellow;
    }
    else {
        # 如果用户不在用户信息列表中,则将用户添加到列表中
        # 这不会影响站点的任何权限
        Write-Host "用户信息列表中未找到用户,因此正在添加..." -ForegroundColor Yellow;
        $user = New-PnPUser -LoginName $UserEmail;

        # 如果找不到用户/电子邮件地址不正确,则返回
        if ($null -eq $user) {
            Write-Error "用户名无效";
            return;
        }
    }

    Write-Host "设置页面头部作者信息..." -ForegroundColor Yellow;

    # 设置PageHeader的Authors和AuthorByLine属性
    # 这两个属性都是字符串属性
    $page.PageHeader.Authors = "[{""id"":""$($user.LoginName)""}]";
    $page.PageHeader.AuthorByLine = "[`"$($user.Email)`"]";

    # 保存更改并发布页面
    $page.Save();
    $page.Publish();

    Write-Host "完成。" -ForegroundColor Green;
    Disconnect-PnPOnline;
}

Set-PageAuthorByline;

来源: 设置页面作者信息

在运行上述脚本之前,您必须按照以下方式安装PnP PowerShell:安装PnP PowerShell

英文:

You can use PnP PowerShell to set SharePoint page Author Byline. Here's the sample PnP PowerShell script for same:


    Param(
        [Parameter(mandatory = $true)]
        [string]$SiteUrl,
        [Parameter(mandatory = $true)]
        [string]$PageName,
        [Parameter(mandatory = $true)]
        [string]$UserEmail
    )

    function Set-PageAuthorByline {

        # Connect to the site
        Connect-PnPOnline -Url $SiteUrl;

        # If there is an error in the connection then return
        if ($null -eq $(Get-PnPConnection).ConnectionType) {
            return;
        }

        # Get the page object from the specified page name / url 
        $page = Get-PnPPage -Identity $PageName;

        # Return if page is not found
        if ($null -eq $page) {
            Write-Error "Page Name is not valid";
            return;
        }

        # Get the required user from the User Information list
        Write-Host "Getting user information from User Information list..." -ForegroundColor Yellow;
        $user = Get-PnPUser | Where-Object Email -eq $UserEmail;

        if ($null -ne $user) {
            Write-Host "Got user information from User Information list." -ForegroundColor Yellow;
        }
        else {
            # If not user is not present in User Information list then add the user to the list
            # This will not affect any permissions to the site
            Write-Host "User information not present in User Information list, hence adding..." -ForegroundColor Yellow;
            $user = New-PnPUser -LoginName $UserEmail; 

            # Return if the user is not found / email address is incorrect
            if ($null -eq $user) {
                Write-Error "User Name is not valid";
                return;
            }
        }

        Write-Host "Setting page header author..." -ForegroundColor Yellow;

        # Set the Authors and AuthorByLine properties of the PageHeader
        # Both these are string properties
        $page.PageHeader.Authors = "[{`"id`":`"$($user.LoginName)`"}]";
        $page.PageHeader.AuthorByLine = "[`"$($user.Email)`"]";

        # Save the chnages and publish the page
        $page.Save();
        $page.Publish();

        Write-Host "Done." -ForegroundColor Green;
        Disconnect-PnPOnline;
    }

    Set-PageAuthorByline;

    # Set-Page-Author-Byline.ps1 -SiteUrl https://tenantname.sharepoint.com/sites/sitename -PageName Page-1.aspx -UserEmail user@tenantname.onmicrosoft.com

Source: Set Page Author Byline

Before running above script, you have to install PnP PowerShell by following: Installing PnP PowerShell

huangapple
  • 本文由 发表于 2023年7月12日 21:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定