我需要使用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
试试这个:
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!"
}