Monday, October 21, 2013

Update Hyperlink Field in SharePoint with PowerShell

I want to change the URL in list item from to using Powershell script

1) copy & paste (change the URLs and Listnames and field) the below script and name it with extension .ps1 (ex: ItemURLChange.ps1)

#Add-PSSnapin Microsoft.SharePoint.PowerShell

$siteUrl = "http://sharepoint/SiteCollection/SiteName"
$webName = “SiteName”
$listName = "Name of your list"
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb($webName)
$spList = $spWeb.Lists[$listName]

foreach($Item in $spList.Items )
$ofldurl= new-object Microsoft.SharePoint.SPFieldUrlValue($Item["URL"])

$ofldurl.URL = $ofldurl.URL.Replace("Texas", "ta")
$ofldurl.Description = $ofldurl.Description.Replace("Texas", "ta")

$item["URL"] = $ofldurl


2) Open the Powershell command and run using the below command

PS C:\temp> ./ItemURLChange

No comments:

Post a Comment