How to create a SharePoint list item with a PowerShell script without installing module(s)

CodeMeUp 20 Reputation points
2025-01-27T22:55:17.97+00:00

Hello!

Has anyone figured out how to create a new SharePoint list item via PowerShell script WITHOUT having to install modules?

I have a simple 4-column SharePoint list & need to add records to it via PowerShell script. Most of the documentation/syntax I've found via googling requires installing modules, but I'd like to believe there's a simpler method for just hopping into a SharePoint list & populating 4 columns.

Any guidance would be most appreciated, thanks in advance!

Microsoft 365 and Office | SharePoint | Development
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 51,846 Reputation points Microsoft External Staff
    2025-01-28T08:06:10.2933333+00:00

    Yes, you can create SharePoint list items via PowerShell without installing any additional modules like the SharePoint PnP PowerShell module.

    Using CSOM via PowerShell, which allows you to interact with SharePoint without requiring any additional modules. The key is to use the SharePoint CSOM libraries, which are already available.

    Here are steps to create SharePoint list items by using CSOM.

    1.Download the SharePoint Online CSOM assemblies (DLLs) if they’re not already installed on your machine. You can get them from: SharePoint Online Client Components SDK

    2.Example script that add an item to a SharePoint list using CSOM in PowerShell.

    # Define variables
    $siteUrl = "https://tenant.sharepoint.com/sites/site"
    $listName = "ListName"
    $userName = "******@yourdomain.com"
    $password = "password"  
    
    # Path to SharePoint CSOM Assemblies
    $csomPath = "C:\Path\To\Microsoft.SharePoint.Client.dll"
    $csomClientRuntimePath = "C:\Path\To\Microsoft.SharePoint.Client.Runtime.dll"
    
    # Load the necessary assemblies
    Add-Type -Path $csomPath
    Add-Type -Path $csomClientRuntimePath
    
    # Create a secure password
    $securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
    
    # Set up credentials
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $securePassword)
    
    # Connect to SharePoint Site
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
    $context.Credentials = $credentials
    
    # Get the list by name
    $list = $context.Web.Lists.GetByTitle($listName)
    
    # Create a new list item
    $newItem = $list.AddItem([Microsoft.SharePoint.Client.ListItemCreationInformation]::new())
    
    # Set values for the columns (assuming your columns are "Title", "Column1", "Column2", and "Column3")
    $newItem["Title"] = "Sample Title"
    $newItem["Column1"] = "Value1"
    $newItem["Column2"] = "Value2"
    $newItem["Column3"] = "Value3"
    
    # Update the list item
    $newItem.Update()
    
    # Execute the request to SharePoint
    $context.ExecuteQuery()
    
    Write-Host "Item added successfully!"
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Kavya 490 Reputation points
    2025-01-28T08:06:51.0566667+00:00

    To work with PowerShell, you must install SharePoint Online Management module or PnP PowerShell module.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.