使用 PowerShell 获取/设置 SharePoint 中的超链接字段值
要求: PowerShell 获取和更新 SharePoint 中的超链接 URL 字段值
以下是用于获取和设置超链接列值的 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!"
}
