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

[玩转系统] 使用 PowerShell 获取/设置 SharePoint 中的超链接字段值

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

使用 PowerShell 获取/设置 SharePoint 中的超链接字段值


要求: PowerShell 获取和更新 SharePoint 中的超链接 URL 字段值

[玩转系统] 使用 PowerShell 获取/设置 SharePoint 中的超链接字段值

以下是用于获取和设置超链接列值的 PowerShell 脚本:

使用 PowerShell 获取超链接字段值

以下是如何使用 PowerShell 获取 SharePoint 超链接字段的 URL 值:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://intranet.crescent.com/"
$ListName = "UserProfiles"
$FieldName="Picture"

#Get the Web, List Objects
$web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)

If($list)
{
    foreach($Item in $List.Items)
    {
        #Get the Hyperlink column
        $Picture = New-Object Microsoft.SharePoint.SPFieldUrlValue($Item[$FieldName])
        #Get the URL of the Hyperlink
        $Picture.URL
        #Get the Decription - Title
        $Picture.Description
    }        
}

使用 PowerShell 更新超链接字段值:

这里是设置超链接字段的SharePoint PowerShell。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "https://intranet.crescent.com/"
$ListName = "UserProfiles"
$FieldName="Picture"

#Get the Web, List Objects
$web = Get-SPWeb $SiteURL
$List = $Web.Lists.TryGetList($ListName)

If($list)
{
    #sharepoint powershell update hyperlink field
    $Picture = New-Object Microsoft.SharePoint.SPFieldURLValue
    $Picture.Description = "Profile Picture"
    $Picture.URL = "https://intranet.crescent.com/UserProfiles/Images/profile.jpg"
    
    #Add new List Item
    $Item = $List.AddItem()
    $Item[$FieldName] = $Picture
    $Item.Update()  
    
    Write-host "New Item Added Successfully!"
}

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

取消回复欢迎 发表评论:

关灯