Forum Discussion
getting all lists within a subweb
Try the below. Currently it seems -web is not working, alternatively you can connect to each subsite and then get the lists in those subsite.
$cred= Get-Credential
connect-pnponline -Url https://tenantname.sharepoint.com/sites/contosobeta -Credentials $cred
$subwebs=Get-PNPSubWebs -Recurse
foreach($subweb in $subwebs)
{
Connect-PNPonline -Url $subweb.Url -Credentials $cred
Get-PnPList
}- Nigel PriceMay 19, 2017Iron Contributor
Hi NarasimaPerumal Chandramohan
it looks as if this might be a timing problem. If I run the two commands (Connect-PnPOnline and Get-PnPList) in a PowerShell (.ps1) file I get the error. If I run the two commands using the PowerShell Gui and typing them in then all works well.
Is there anyway I can get the second command wait until the first command finishes (or even run on a single thread.) ? If this was JavaScript ot TypeScript, then I could use promises. But in PowerShell ?
Regards
Nigel
- Nigel PriceMay 19, 2017Iron Contributor
Hi NarasimaPerumal Chandramohan
I have $lists = Get-PnPList
I tried that and when I went to access the $lists I got this ->
format-default : The collection has not been initialized. It has not been requested or the request has not been
executed. It may need to be explicitly requested.
+ CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Comma
nds.FormatDefaultCommandRegards
Nigel