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

[玩转系统] 使用 PowerShell 将新项目添加到 SharePoint 中的链接列表

作者:精品下载站 日期:2024-12-14 13:45:57 浏览:13 分类:玩电脑

使用 PowerShell 将新项目添加到 SharePoint 中的链接列表


您是否正在寻找一种使用 PowerShell 将新项目添加到 SharePoint 链接列表的快速方法?让我向您展示如何使用 PowerShell 在 SharePoint 中创建新列表项:

以下是将新项目添加到 SharePoint 链接列表的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to add new item to SharePoint link list
Function Add-LinkListItem($WebURL, $ListName, $LinkURL, $LinkTitle)
{
    try
    {
        $ErrorActionPreference ="Stop" 

        #Get the Web
        $Web = Get-SPWeb $WebURL

        #Get the link list
        $List = $web.lists[$ListName]
        
        #Create a new item
        $NewItem = $list.Items.Add()
 
        #Add properties to this list item
        $NewItem["URL"] = "$($LinkURL), $($LinkTitle)"

        #Update the object so it gets saved to the list
        $NewItem.Update()
        
        write-host "New Item has been Added to the List!"-foregroundcolor Green
    }
    catch [System.SystemException]
    {
        write-host "New Item Creation failed due to:" $_.Exception.Message -foregroundcolor Red
    }
    finally
    {
        #Dispose web object
        $web.Dispose()
        $ErrorActionPreference ="Continue" 
    }
}

#Call the function to Add new list item
Add-LinkListItem "https://sharepoint.crescent.com/" "Quick Links" "https://intranet.crescent.com" "Crescent Intranet"

和输出:

[玩转系统] 使用 PowerShell 将新项目添加到 SharePoint 中的链接列表

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

取消回复欢迎 发表评论:

关灯