feedthemachine
feedthemachine

Reputation: 620

Execute command in Read-host

In PowerShell 5.1.17763.1490, I want to display a list of names in the Read-Host commandlet

Connect-PnPOnline -Url $webUrl -Credentials (Get-Credential)
$availableLists = Get-PNPList | select Title
$listName = Read-Host "Enter list name (e.g. Documents). Available lists are: $availableLists" 

Currently, it prints something like this:

Enter list name (e.g. Documents). Available lists are:                        : 

Yet I expect it to print:

Enter list name (e.g. Documents). Available lists are: Documents, Form Templates, LibOne:

I can return all these list names by executing Get-PNPList | select Title

Upvotes: 1

Views: 237

Answers (1)

feedthemachine
feedthemachine

Reputation: 620

$availableLists = (Get-PNPList).Title -join ', '
$listName = Read-Host "Enter list name (e.g. Documents). Available lists are: $availableLists"

did the trick.

Upvotes: 2

Related Questions