Testing with Chuck

Sometimes you need to populate your SharePoint list with test data in order to test how your custom functionality works when there are more then four items added to the list. Of course it’s easy to add the required test data using PowerShell and populate the list with like test item #1, test item #2, test item #3, and so on…

However looking at that kind of test items gets boring quite fast. To fix this we can utilize the magnificient The Internet Chuck Norris Database to load a lot more interesting test values in our list.

Chuck and SharePoint
Chuck Norris and SharePoint cartoon by Dan Lewis

First you need to install the OfficeDevPnP.PowerShell Commands on your computer unless you’ve already done that. These CmdLets make writing SharePoint related scripts so much easier and even Chuck Norris can’t live without them. Then start up PowerShell and run the following script to add Chuck related testdata to your SharePoint list.

$siteUrl = "https://contoso.sharepoint.com/sites/sitename"
$listname = "ChuckFacts"
$icndbUrl = "http://api.icndb.com/jokes"

$credential = Get-Credential
Connect-SPOnline -Url $siteUrl -Credentials $credential
Invoke-RestMethod -Uri $icndbUrl | Select -ExpandProperty value | ForEach-Object {
    $fact = [system.web.httputility]::htmldecode($_.joke).Trim();
    if ($fact.Length -lt 256) {
        Add-SPOListItem -List $listname -Values @{"Title" = $fact }

Once again Chuck Norris has saved our day and the world is a safe place again. Happy testing!

Leave a Comment