I have to functions. In the first, I create a reference to a SharePoint list. I would like to pass the list to a second function. In the second functions list of parameters, I declare it as String

This doesn't work. How do I declare the parameter as being a list?

function GetList()
    [string] $listID,
    [string] $listName
    Write-Host "Provided ListName: " $listName -ForegroundColor Cyan
    Write-Host "The list id is: " $listID -ForegroundColor Red

    $list = Get-PnPList -Identity $listName

     CreateView -list $list


function CreateView() 
    [string] $list

    Add-PnpView -Title "Test View" -List $list -Fields "Title"
    Write-Host "Creating New View"

As per the official documentation below:


  1. Returns a List Object

  2. And outputs Microsoft.SharePoint.Client.List

So instead of using it as a string try using its return type you get.

You can also get the type returned from Get-PnPList, using:

  • Excellent! Thanks. Makes perfect sense! – Martin Muldoon Aug 14 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.