Skip to main content
Skip table of contents

Sharepoint fields mapping PowerShell

Use this script to test SharePoint credentials, site paths, list names, and to collect a list of SharePoint field names and their related display names in a paste-able format for use in the iPaaS node’s settings when setting fields.

The output will resemble:

CODE
{
    "Received_x0020_By":  "Received By",
    "Location":  "Location",
    "Manufacturer_x0020_Lot":  "Manufacturer Lot",
}

Where the key is the field name, and the value is the display name. Copy the output use the keys and replace the values with Square 9 notation where appropriate.

POWERSHELL
#Requires -Version 5.1
# Get-ListFields.ps1
# Prints a SharePoint list's editable fields as a JSON object: { "<internalName>": "<displayName>", ... }
#
# Run it:
#   powershell -File .\Get-ListFields.ps1          (Windows)
#   pwsh ./Get-ListFields.ps1                       (macOS/Linux)
#   ... -Verbose                                    also prints each Graph URL


[CmdletBinding()]
param()

$tenantId = (Read-Host "Tenant ID").Trim()
$clientId = (Read-Host "Client ID").Trim()
$sitePath = (Read-Host "Site path (e.g. contoso.sharepoint.com:/sites/Team)").Trim()
$listName = (Read-Host "List name").Trim()

# Get-Credential's password box accepts paste reliably (Read-Host -AsSecureString often eats it on Windows).
$cred = Get-Credential -UserName $clientId -Message "Paste the client secret into the Password box"
if (-not $cred) { throw "No client secret provided." }
# Cross-platform SecureString -> plaintext (PtrToStringAuto mis-decodes on macOS/Linux)
$clientSecret = ([System.Net.NetworkCredential]::new('', $cred.Password)).Password.Trim()

$graph = "https://graph.microsoft.com/v1.0"

function Invoke-Graph($uri, $headers) {
    Write-Verbose "GET $uri"
    Invoke-RestMethod -Headers $headers -Uri $uri -ErrorAction Stop
}

try {
    # 1. Authenticate (client credentials)
    $token = (Invoke-RestMethod -Method Post `
        -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" `
        -ContentType "application/x-www-form-urlencoded" `
        -Body @{
            grant_type    = "client_credentials"
            client_id     = $clientId
            client_secret = $clientSecret
            scope         = "https://graph.microsoft.com/.default"
        }).access_token
    $headers = @{ Authorization = "Bearer $token" }

    # 2. Resolve site id
    $siteId = (Invoke-Graph "$graph/sites/$sitePath" $headers).id

    # 3. Resolve list id by display name (filter, with client-side fallback)
    $esc  = $listName.Replace("'", "''")
    $list = (Invoke-Graph "$graph/sites/$siteId/lists?`$select=id,name,displayName&`$filter=displayName eq '$esc'" $headers).value | Select-Object -First 1
    if (-not $list) {
        $list = (Invoke-Graph "$graph/sites/$siteId/lists?`$select=id,name,displayName" $headers).value |
            Where-Object { $_.displayName -eq $listName -or $_.name -eq $listName } | Select-Object -First 1
    }
    if (-not $list) { throw "List '$listName' not found on site '$sitePath'." }

    # 4. Get columns, keep editable ones, emit name -> displayName map
    $columns = (Invoke-Graph "$graph/sites/$siteId/lists/$($list.id)/columns?`$select=name,displayName,readOnly,hidden" $headers).value
    $map = [ordered]@{}
    foreach ($c in ($columns | Where-Object { -not $_.readOnly -and -not $_.hidden })) {
        $map[$c.name] = $c.displayName
    }
    $map | ConvertTo-Json
}
catch {
    Write-Error "Failed: $($_.Exception.Message)"
    if ($_.ErrorDetails.Message) { Write-Error $_.ErrorDetails.Message }
    exit 1
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.