Write random items into a SharePoint list


This PowerShell script writes items to a specified SharePoint list.

NOTE: This was tested on an on-premise SharePoint 2013 installation.

## Write items to a list

Add-PSSnapin Microsoft.SharePoint.PowerShell

[System.String]$siteUrl = "https://sharepoint/sites/spsite"
[System.String]$listTitle = "list"

[Microsoft.SharePoint.SPSite]$SPSite = Get-SPSite -Identity $siteUrl
[Microsoft.SharePoint.SPWeb]$SPWeb = $SPSite.RootWeb
[Microsoft.SharePoint.SPList]$SPList = $SPWeb.Lists[$listTitle]
[Microsoft.SharePoint.SPListItem]$SPListItem = $null

[System.String]$prefix = "Item No"

# Loop forever (Ctrl-C to stop the script)
while ( 1 -eq 1 ) {
    [System.String]$value = "$($prefix) - $(random)"
    Write-Output "Creating item $($value)"
    $SPListItem = $SPList.Items.Add()
    $SPListItem['Title'] = $value


About Author

Christian Unnerstall

Christian Unnerstall, founder of devshooin.com, enjoys designing and building things that look nice and work well, whether it's websites or services within the interwebs. Have questions - feel free to reach out to him. Enjoy

Leave a Reply