【问题标题】:Setting the "Description" on a Document Library using PnP PowerShell for SharePoint Online使用 PnP PowerShell for SharePoint Online 在文档库上设置“描述”
【发布时间】:2017-09-25 00:30:30
【问题描述】:

我正在尝试使用 PnP-PowerShell 命令在 SharePoint Online 中的文档库上设置描述,但它似乎在工作中非常断断续续,所以我想检查一下正确的方法是什么?

我创建了一个新库:

New-PnPList -Template DocumentLibrary -Title "TempLibrary"

然后尝试设置描述:

$l = Get-PnPList -Identity TempLibrary
$l.Description = "My Description Here"

现在显然这不起作用,因为我需要使用我假设的 CSOM 将更改发回?

然后我尝试了以下方法:

$ctx = Get-PnPContext
$l = Get-PnPList -Identity TempLibrary
$l.Description = "My Description Here"
$ctx.ExecuteQuery()

但这似乎仍然不起作用。

任何人对如何可靠地做到这一点的任何想法将不胜感激。

非常感谢, D.

更新

Eurgh...这似乎可行,但这是对的吗?是预期的吗?感觉不是很像 PowerShell...

New-PnPList -Title "Test5" -Template DocumentLibrary
$t = Get-PnPList -Identity Test5
$ctx.Load($t)
$ctx.ExecuteQuery()
$t.Description = "Test5 Description"
$t.Update()
$ctx.ExecuteQuery()

【问题讨论】:

    标签: powershell sharepoint csom


    【解决方案1】:

    如果不加载列表,您将无法设置描述或其他属性,因此代码是正确的。

    $ctx.Load($t)
    

    为什么你觉得这不像PS? :) 好奇...

    【讨论】:

    • 真的不知道。我想我只是假设可能有一个Set-PnPListProperty 命令或可以让您设置属性并执行加载和执行查询命令的东西。毕竟,我在使用其他 Set-PnP* 命令时不必使用 Load 和 ExecuteQuery...
    【解决方案2】:

    使用以下脚本。希望对您有所帮助。

        Add - PSSnapin Microsoft.SharePoint.PowerShell  
    
        function CreateList($spWeb, $listName) 
        {   
            $spTemplate = $spWeb.ListTemplates["Document Library"]  
            $spListCollection = $spWeb.Lists  
            $spListCollection.Add($listName, $listName, $spTemplate)  
        }  
    
        Function SetDescription($spWeb, $listName)
        {            
            $path = $spWeb.url.trim()  
            $spList = $spWeb.GetList("$path/Lists/$listName")
            $spList.Description = "--Your Desired Description--"
            $spList.Update()
        }
    
    
        $siteCollectionUrl = "--Your Site Collection Url--"  
        $listName = "--Your Desired List Name--"  
        $spWeb = Get - SPWeb - Identity $siteCollectionUrl 
    
        CreateList $spWeb $listName 
    
        SetDescription $spWeb $listName
    

    【讨论】:

    • 这不是 PNP,它远程连接到 SharePoint 而不必在 SharePoint 服务器上。如果您没有服务器访问权限并希望在网站集中工作,则非常有用。在这里阅读更多link
    猜你喜欢
    • 2018-03-05
    • 2021-05-05
    • 2021-03-18
    • 2018-12-17
    • 2016-07-05
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    相关资源
    最近更新 更多