SharePoint Online: Add Hyperlink or Picture Column to List using PowerShell

Requirement: Add a hyperlink column to SharePoint Online list.

The Hyperlink or Picture column in SharePoint Online is used to store URLs of web addresses or pictures. The field type can be configured to either URL or Picture.

  • Browse to your SharePoint Online site and navigate to the target list in which you want to add a hyperlink or picture column.
  • Under the List tab, click on the “Create Column” button in the ribbon.
  • Provide the Name to your new column, specify the type as “Hyperlink or Picture”. Select the format of the URL as either Hyperlink or Picture from the “Format URL as” dropdown. Add Hyperlink or Picture Column to SharePoint Online List using PowerShell
  • Fill other optional values such as Field description, Required, and Add to default view settings.  Click on “OK” to create a Hyperlink or Picture field in the SharePoint Online list.

Here is the PowerShell script to add hyperlink field to SharePoint Online list. Just set the parameters accordingly and run the script.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Custom function to add column to list
Function Add-HyperLinkPictureColumnToList()
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $Name,
        [Parameter(Mandatory=$true)] [string] $DisplayName,
        [Parameter(Mandatory=$false)] [string] $Description=[string]::Empty,
        [Parameter(Mandatory=$false)] [string] $IsRequired = "FALSE",
        [Parameter(Mandatory=$false)] [string] $Format ="Hyperlink"

    #Generate new GUID for Field ID
    $FieldID = New-Guid

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        #Get the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)

        #Check if the column exists in list already
        $Fields = $List.Fields
        $NewField = $Fields | where { ($_.Internalname -eq $Name) -or ($_.Title -eq $DisplayName) }
        if($NewField -ne $NULL)  
            Write-host "Column $Name already exists in the List!" -f Yellow
            #Define XML for Field Schema
            $FieldSchema = "<Field Type='URL' ID='{$FieldID}' DisplayName='$DisplayName' Name='$Name' Description='$Description' Required='$IsRequired' Format='$Format' />"
            $NewField = $List.Fields.AddFieldAsXml($FieldSchema,$True,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldInternalNameHint)

            Write-host "New Column Added to the List Successfully!" -ForegroundColor Green  
    Catch {
        write-host -f Red "Error Adding Column to List!" $_.Exception.Message

#Set parameter values
$DisplayName="Project Reference"
$Description="Enter the Project Reference"
$Format="Hyperlink" #or "Image"

#Call the function to add column to list
Add-HyperLinkPictureColumnToList -SiteURL $SiteURL -ListName $ListName -Name $Name -DisplayName $DisplayName -Description $Description -Format $Format 

PnP PowerShell to Add URL Column to SharePoint Online List

#Config Variables
$SiteURL = ""
$ListName= "Projects"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Add Hyperlink Field to list
Add-PnPField -Type URL -List $ListName -DisplayName "Company Website" -InternalName "CompanyWebsite" -AddToDefaultView

Similarly, we can create hyperlink field from XML schema.

#Define XML Schema for URL Field
$FieldXML= "<Field Type='URL' Name='CompanyWebsite' ID='$([GUID]::NewGuid())' DisplayName='Company Website' Format='Hyperlink' ></Field>"

#Add URL Field to list
Add-PnPFieldFromXml -FieldXml $FieldXML -List $ListName

Set the Format=’Image’ attribute for Picture field.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “SharePoint Online: Add Hyperlink or Picture Column to List using PowerShell

  • October 10, 2018 at 7:27 AM

    Hi Salaudeen,

    It shows the option for hyperlink, not browse image. How to browse image through Picture column?
    Could you please help me on this.


    • October 10, 2018 at 10:09 AM

      There is no way to do this out of the box. You have to use Custom/3rd party controls.. E.g.


Leave a Reply