0

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()
{
    param(
    [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() 
{
    param(
    [string] $list
    )

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

1 Answer 1

1

As per the official documentation below:

Get-PnPList

  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:

$list.GetType().FullName
1
  • Excellent! Thanks. Makes perfect sense! Commented Aug 14, 2019 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.