Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
54 views
in SharePoint Server by 39 45 54

I'm facing a problem where I'm successfully retrieving the list item, but I can't modify the description of the URL field based on another column for all list items in SharePoint URL using PowerShell,

Here's the code I'm using, but it's not working

$webUrl = "https://yoursite.sharepoint.com/sites/yoursite"
$listTitle = "YourListName"
$itemId = 123

$web = Get-SPWeb $webUrl
$list = $web.Lists[$listTitle]
$item = $list.GetItemById($itemId)

# Attempt to update the description of the URL field
$item["URL_x0020_Field"] = "New Description"
$item.Update()

Any idea How can I update the description of a URL field based on another field for all items in a SharePoint list using PowerShell?


1 Answer

0 like 0 dislike
by 159 186 375

Get URL Field in SharePoint PowerShell

In your case, you need to use Microsoft.SharePoint.SPFieldUrlValue, as stated below

Microsoft.SharePoint.SPFieldUrlValue($Item["URL"])

Update URL Field Description based on existing column using PowerShell

In case you need to loop for each item and update the URL description based on another column, try to use the below PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell
 
$siteUrl = "https://SiteURL"
$webName = “SiteName”
$listName = "Listname"
$spSite = Get-SpSite $siteurl
$spWeb = $spSite.OpenWeb()
$spList = $spWeb.Lists[$listName]
 
            foreach($Item in $spList.Items )
            {
                #The URL field name that you need to update
                $ofldurl= new-object Microsoft.SharePoint.SPFieldUrlValue($Item["URL"])
                
                # The calculated column that hold URL (In case you need to update the URL from existing field as well)
                #$ofldurl.URL = $Item["StringURL"].Replace("string;#","")
                
                # A column name that hold the description
                $ofldurl.Description = $Item["Title"]
 
                Write-Host $ofldurl

                $Item["URL"] = [Microsoft.SharePoint.SPFieldUrlValue]$ofldurl
                $Item.update()
            }
 
       $spWeb.Dispose()

See Also

If you don’t ask, the answer is always NO!
...