当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:用于重命名列表或文档库的 PowerShell

作者:精品下载站 日期:2024-12-14 14:52:29 浏览:16 分类:玩电脑

SharePoint Online:用于重命名列表或文档库的 PowerShell


要求:SharePoint Online PowerShell 重命名列表或文档库。

如何在 SharePoint Online 中重命名列表?

当您在 Microsoft SharePoint Online 中创建列表时,系统会根据列表的标题自动生成名称。在某些情况下,您可能需要重命名该列表。本文将向您展示如何使用经典和现代用户界面重命名 SharePoint Online 列表。我们还将向您展示如何使用 PowerShell 重命名 SharePoint Online 中的列表。

要更改 SharePoint Online 中的列表名称,请执行以下步骤:

  1. 导航到要重命名的 SharePoint Online 列表或库。单击“设置”图标,然后单击“列表设置”(在经典 UI 中,在“列表”选项卡下,单击功能区中的“列表设置”按钮)
  2. 在列表设置页面上,单击“常规设置”标题下的“列表名称、描述和导航”链接。
  3. 在“常规设置”页面上,您可以更新列表的标题,然后单击“保存”以提交更改。

    [玩转系统] SharePoint Online:用于重命名列表或文档库的 PowerShell

这会更改 SharePoint Online 中列表或文档库的名称。

使用 PowerShell 重命名 SharePoint Online 中的列表

现在,让我们引导您完成使用 PowerShell 重命名 SharePoint Online 列表的过程。如果您的列表名称很长或难以记住,或者想要在自动化过程中重命名列表,这会很有帮助。以下是用于更改 SharePoint Online 列表名称的 PowerShell 脚本:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to Rename a SharePoint Online List or library using PowerShell
Function Rename-SPOList
{
    param
    (
        [string]$SiteURL  = $(throw "Please Enter the Site URL!"),
        [string]$ListName = $(throw "Please Enter the List Name to Rename!"),
        [string]$NewName = $(throw "Please Enter the New Name for the List!")
    )
    Try {
        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #Get the List
        $List=$Ctx.Web.Lists.GetByTitle($ListName) 

        $List.Title = $NewName
        $List.Update()
        $Ctx.ExecuteQuery()
            
        Write-Host "List has been Renamed to '$NewName' Successfully!" -ForegroundColor Green  
    }
    Catch {
        write-host -f Red "Error Renaming List!" $_.Exception.Message
    }
}
 
#Call the function to rename a list or library
Rename-SPOList -SiteURL "https://Crescent.sharepoint.com/" -ListName "Documents" -NewName "Team Documents"

该脚本可以快速轻松地重命名您的列表,而无需触摸用户界面。

您还可以使用此 PowerShell 脚本重命名 SharePoint Online 中的文档库!

SharePoint Online:使用 PnP PowerShell 更改列表名称

如果您需要仅使用几行代码重命名 SharePoint Online 中的列表,PnP PowerShell 就是您的最佳选择!以下是如何使用 PnP PowerShell cmdlet Set-PnPList 更改 SharePoint Online 中文档库的名称:


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Rename "Projects" List to "Projects Archive"
Set-PnPList -Identity "Projects" -Title "Projects Archive"

请注意,更改列表标题不会更改列表 URL!如果需要更改 SharePoint Online 列表 URL,请参阅如何使用 PowerShell 更改 SharePoint Online 中的列表 URL?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯