0

I am trying to fix default URL for Hyperlink column in share point list and getting an error. Please help to find the problem.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Configuration Variables $SiteURL = "http://sharepoint-test/sites/name/" $ListName = "Test list" $FieldName= "default" #Get the Web, List Objects $web = Get-SPWeb $SiteURL $List = $Web.Lists.TryGetList($ListName) If($list) { #sharepoint powershell update hyperlink field $Hyperlink = New-Object Microsoft.SharePoint.SPFieldURLValue $Hyperlink.Description = "Profile Picture" $Hyperlink.URL = "http://sharepoint-test/image/profile.jpg" #Add new List Item $Item = $List.AddItem() $Item[$FieldName] = $default $Item.Update(); Write-host "New Item Added Successfully!" } 

Code returns following error:

Exception calling "Update" with "0" argument(s): "Invalid number value. A number field contains invalid data. Please check the value and try again."

At C:\Users\testuser\Code\test.ps1:22 char:5 + $Item.Update(); + ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException

    2 Answers 2

    0

    You tag says "sharepoint-online". The cmdlets in your samples are for SharePoint on-prem and are typically run on the SharePoint server.

    Take a look at the PNP cmdlet library for maintaining sites (webs) and lists in both SharePoint Online and on-prem.

    https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

    For tenant admin and creating Site Collections use the SPO cmdlets:

    https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/introduction-sharepoint-online-management-shell?view=sharepoint-ps

    Here's an example using PNP to add an item:

    Connect-PnPOnline https://yourDomain/sites/yourSite Add-PnPListItem -List "Announcements" -Values @{"Title" = "Test Title"; "Body"="hello world"} 
    1
    • Hi Mike, Its SP 2013 environment. please suggest moreCommentedApr 3, 2019 at 2:50
    0

    We can use the PowerShell below to achieve it.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Configuration Variables $SiteURL = "http://sharepoint-test/sites/name/" $ListName = "Test list" $FieldName= "default" #Get the Web, List Objects $web = Get-SPWeb $SiteURL $List = $Web.Lists.TryGetList($ListName) If($list) { #sharepoint powershell update hyperlink field $Hyperlink = New-Object Microsoft.SharePoint.SPFieldURLValue $Hyperlink.Description = "Profile Picture" $Hyperlink.URL = "http://sharepoint-test/image/profile.jpg" #Add new List Item $Item = $List.AddItem() $Item["Title"]="new item" $Item[$FieldName] = $Hyperlink.ToString() $Item.Update() Write-host "New Item Added Successfully!" } 

    enter image description here

    0

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.