PnP PowerShell to fill video playlist in SharePoint Online

if (!$creds)
{ $creds = Get-Credential; }

function AddItemToPlaylist($sourceSiteUrl, $sourceListName, $sourceItemId, $targetSiteUrl, $targetPlaylistName)
{ Write-Host "Connecting to source site.";

Connect-PnPOnline -Url $sourceSiteUrl -Credentials $creds;

$site = Get-PnPSite -Includes ID;

$list = Get-PnPList -Identity $sourceListName;

$item = Get-PnPListItem -List $list -Id $sourceItemId;
Get-PnPProperty -ClientObject $item -Property 'File';
Get-PnPProperty -ClientObject $list -Property 'ParentWeb';

$siteId = $site.Id;
$listId = $list.Id;
$title = $item.File.Title;
$uniqueId = $item.File.UniqueId;
$Id = $item.Id;
$webAbsoluteUrl = $list.ParentWeb.Url;
$listFullUrl = $webAbsoluteUrl + $list.RootFolder.ServerRelativeUrl;
$webDavURL = $webAbsoluteUrl + $item.File.ServerRelativeUrl;
$duration = $item.FieldValues.MediaLengthInSeconds;

$thumbnailLink = "$webAbsoluteUrl/_api/v2.0/sites/$siteId/lists/$listId/items/$uniqueId/driveItem/thumbnails/0/c90x150/content?preferNoRedirect=true";

$ts =  [timespan]::fromseconds($duration);
$durationString = $ts.ToString("hh\:mm\:ss");

Write-Host "Connecting to target playlist";

Connect-PnPOnline -Url $targetSiteUrl -Credentials $creds;

$targetList = Get-PnPList -Identity $targetPlaylistName;

$aVidIdentifiers = @{ "UniqueId"=$uniqueId;
                        "Id"=$Id;
                        "WebAbsoluteUrl"=$webAbsoluteUrl;
                        "ListFullUrl"=$listFullUrl;
                        "WebDavUrl"=$webDavURL
                    };

$values = @{
    "Thumbnail" = $thumbnailLink;
    "Title" = $title;
    "Owner" = "";
    "Duration" = $durationString;
    "VideoIdentifiers" = ConvertTo-Json -InputObject $aVidIdentifiers;
    "ContentType" = "Item"
};

Write-Host "Creating playlist item. This will give an error but it works.";

Add-PnPListItem -List $targetList -Values $values;

Write-Host "Finished creating playlist item" -ForegroundColor Green;

}

AddItemToPlaylist -sourceSiteUrl "https://yourtenant.sharepoint.com" -sourceListName "Documents" -sourceItemId 5 -targetSiteUrl "https://yourtenant.sharepoint.com/sites/jwtestgroup/" -targetPlaylistName "Rabbits JW Test group";