powershell - 使用 PowerShell 脚本修复 SharePoint 2013 列表中超链接列的默认 URL
问题描述
我需要使用 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!"
}
推荐阅读
- python - os.replace() 和 os.rename() 的区别?
- oauth-2.0 - 在 oauth2-proxy 的上游服务中使用访问令牌进行授权?
- arrays - 如果具有相似的 id,请快速将结构模型更改为另一个模型
- java - Apache-Pulsar 模式没有方法 builder()
- node.js - 动态数据库连接续集
- node.js - 有没有办法从 Node fetch 请求公共网站的内部 API?
- keras - 如何训练具有多个值的输出模型
- sql - 按 A 列分组并计算 SQL 中 B 列的值计数
- python - 有没有办法将 fxml 加载到 jython 逻辑代码中?
- r - 我在这个闪亮的仪表板 UI 代码中缺少什么?