Forum Discussion
Site Collection: Get Web Id fails
Hi Guys,
I am using below code to get web Id of list of site collections using code below. The issue is i always get GUID of the first site collection howerver the other webinfo like Title, Url,etc. is correct. can anyone suggest me what is going wrong here:
foreach ($row in $data)
{
Connect-PnPOnline -Url $row.Url -Credentials $creds
$web=Get-PnPWeb
write-host "web: " + $web.Title
write-host "web: " + $web.id
}
12 Replies
Faced similar issue in the past, just initially $web with null as below and check.
foreach ($row in $data) { Connect-PnPOnline -Url $row.Url -Credentials $creds $web=Get-PnPWeb write-host "web: " + $web.Title write-host "web: " + $web.id $web=$null }
- nileshvkCopper Contributor
Hi Narsima,
I have tried this already. No luck with this change.
Get-PnPWeb gets the web within the current site.
You want to use Get-PnPSubWebs to get all subwebs.
then select the one that you want by
Get-PnPSubWebs | where { $_.Title -eq "sitetitle"}
- nileshvkCopper Contributor
There are 2 properties of site collection. Site Id & Web Id.
I want to find out web id of list of site collections. Above code gives me Title of web(site Collection) but fails for Web ID.
I hope it is clear.
Which version of PnP PowerShell are you using. I'm using the September release and Id is coming back without any problem.