使用PowerShell脚本修复SharePoint 2013列表中的超链接列的默认URL

问题描述 投票:0回答:2

我需要使用PowerShell脚本修复SharePoint 2013列表中的超链接列的默认URL。我正在尝试下面的PowerShell脚本并收到错误。

PowerShell脚本:

$myweb= Get-SPWeb http://sharepointtest/sites/test/
$mylist = $myweb.Lists["Test list"]
$myFieldName = $mylist.Fields["hyperlink"]
$defaultValue=$myFieldName.DefaultValue
$myFieldName.DefaultValue = 'https://www.google.com/'
$myFieldName.Update()
Write-Host 'complete'

错误信息:

The property 'DefaultValue' cannot be found on this object. Verify that the
property exists and can be set.
At C:\Users\spsetup\Code\defaultvalue.ps1:5 char:1
+ $myFieldName.DefaultValue = 'https://www.google.com/'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Users\spsetup\Code\defaultvalue.ps1:6 char:1
+ $myFieldName.Update()
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
powershell sharepoint sharepoint-2013 sharepoint-designer
2个回答
0
投票

试试这个:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://sharepointtest/sites/test/"
$ListName = "Test list"
$FieldName="hyperlink"

#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 = "hyperlink"
    $Picture.URL = "http://sharepointtest/sites/test/Images/profile.jpg"

    #Add new List Item
    $Item = $List.AddItem()
    $Item[$FieldName] = $Picture
    $Item.Update() 

    Write-host "New Item Added Successfully!"
}

0
投票

根据您的描述,我的理解是您正在尝试为超链接字段设置默认值。不幸的是,使用SharePoint UI是不可能的。但仍然可以使用InfoPath中的InfoPath.edit列表,然后右键单击“字段”面板中的“超链接”或“图片”字段。选择“字段属性”,然后可以设置字段的默认值。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.