Site Collection: Get Web Id fails

%3CLINGO-SUB%20id%3D%22lingo-sub-107158%22%20slang%3D%22en-US%22%3ESite%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107158%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%20below%20code%20to%20get%20web%20Id%20of%20list%20of%20site%20collections%20using%20code%20below.%20The%20issue%20is%20i%20always%20get%20GUID%20of%20the%20first%20site%20collection%20howerver%20the%20other%20webinfo%20like%20Title%2C%20Url%2Cetc.%20is%20correct.%20can%20anyone%20suggest%20me%20what%20is%20going%20wrong%20here%3A%3C%2FP%3E%3CP%3Eforeach%20(%24row%20in%20%24data)%3CBR%20%2F%3E%7B%3C%2FP%3E%3CP%3EConnect-PnPOnline%20-Url%20%24row.Url%20-Credentials%20%24creds%3CBR%20%2F%3E%24web%3DGet-PnPWeb%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%20%22web%3A%20%22%20%2B%20%24web.Title%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ewrite-host%20%22web%3A%20%22%20%2B%20%24web.id%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107786%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107786%22%20slang%3D%22en-US%22%3E%3CP%3EI%20can%20confirm%20that%20there%20are%20bunch%20of%20site%20collections%20which%20has%20same%20Web%20Id.%202%20things%20i%20want%20to%20mention%20here%3A%201)%20we%20have%20created%20these(bulk)%20site%20collections%20using%20PowerShell%3C%2FP%3E%3CP%3E2)%20We%20are%20migrating%20data%20from%20SharePoint%202007%20to%20these%20site%20collections.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107763%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107763%22%20slang%3D%22en-US%22%3E%3CP%3EDo%20all%20you%20site%20collection%20have%20this%20problem%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20script%20below%20should%20list%20all%20your%20rootwebs%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24cred%20%3D%20Get-Credential%20-Message%20%22Password%22%20-UserName%20admin%40mytenant.onmicrosoft.com%0AConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%20-Credentials%20%24cred%0A%0A%24sites%20%3D%20Get-PnPTenantSite%20%0A%0Aforeach%20(%24site%20in%20%20%24sites)%20%7B%20%0A%20%20%20Connect-PnPOnline%20%24site.Url%20-Credentials%20%24cred%0A%0A%20%20%20%24web%20%3D%20Get-PnPWeb%20%0A%20%20%20%24web%0A%7D%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107483%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107483%22%20slang%3D%22en-US%22%3E%3CP%3EThese%20are%20site%20collections.%20Itried%20this%3A%3C%2FP%3E%3CPRE%3EConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%2FSites%2FSite1%20-Credentials%20%24cred%0A%0AGet-PnPWeb%0A%20%0AConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2Fsite2%20-Credentials%20%24cred%3CBR%20%2F%3EGet-PnPWeb%3C%2FPRE%3E%3CP%3Eand%20I%20get%20%3A%3C%2FP%3E%3CPRE%3ETitle%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A-----%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20---------------------%20--%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0ASite%201%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e19d8f5e-d966-44f7-829b-c9cd39a2c462%0ASite%202%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e19d8f5e-d966-44f7-829b-c9cd39a2c462%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2387%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%20wrote%3A%3CBR%20%2F%3E%3CP%3EAre%20those%20site%20collections%20or%20sites%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20ran%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%20-Credentials%20%24cred%0A%0AGet-PnPWeb%0A%20%0AConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2Fsite2%20-Credentials%20%24cred%0A%0AGet-PnPWeb%0A%0ATitle%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ServerRelativeUrl%20Id%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A-----%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-----------------%20--%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AMy%20Team%20Site%20%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e19d8f5e-d966-44f7-829b-c9cd39a2c462%0ASite%202%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fsites%2Fsite2%20%20%20%200b3bc433-e3f1-4415-9154-97b624a59189%3C%2FPRE%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CP%3E%3CSTRONG%3EThere%20are%20multiple%20site%20collections%20whhich%20has%20same%20Web%20Id.%20However%20Site%20Id%20is%20different%20for%20all%20the%20site%20collections.%20Also%20Sub%20Site's%20has%20unique%20ID's.%20This%20looks%20weird%20to%20me.%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107478%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107478%22%20slang%3D%22en-US%22%3E%3CP%3EAre%20those%20site%20collections%20or%20sites%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20ran%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%20-Credentials%20%24cred%0A%0AGet-PnPWeb%0A%20%0AConnect-PnPOnline%20https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2Fsite2%20-Credentials%20%24cred%0A%0AGet-PnPWeb%0A%0ATitle%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ServerRelativeUrl%20Id%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A-----%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-----------------%20--%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0AMy%20Team%20Site%20%2F%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e19d8f5e-d966-44f7-829b-c9cd39a2c462%0ASite%202%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2Fsites%2Fsite2%20%20%20%200b3bc433-e3f1-4415-9154-97b624a59189%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107460%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107460%22%20slang%3D%22en-US%22%3E%3CP%3EI%20opened%204-5%20site%20collections%20in%20SharePoint%20Online%20Client%20Browser%20and%20they%20are%20showing%20same%20Web%20Id%20for%20all%20the%20site%20collections.%20In%20the%20screen%20shot%20below%20I%20am%20assuming%20Level%201%20as%20Site%20Id%20and%20Level%202%20as%20Web%20Id.%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F20272iD978D4D1339B0EFD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Untitled.png%22%20title%3D%22Untitled.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107448%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107448%22%20slang%3D%22en-US%22%3E%3CP%3EI%20tried%20with%20%3CSPAN%3ESeptember%26nbsp%3Brelease.%20Still%20no%20luck.%20Are%20you%20providing%20list%20of%20site%20collections%20to%20the%20script%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107425%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107425%22%20slang%3D%22en-US%22%3E%3CP%3EWhich%20version%20of%20PnP%20PowerShell%20are%20you%20using.%20I'm%20using%20the%20September%20release%20and%20Id%20is%20coming%20back%20without%20any%20problem.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107377%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107377%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Narsima%2C%3C%2FP%3E%3CP%3EI%20have%20tried%20this%20already.%20No%20luck%20with%20this%20change.%3C%2FP%3E%3CDIV%20class%3D%22lia-message-author-avatar%20lia-component-author-avatar%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107375%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107375%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20are%202%20properties%20of%20site%20collection.%20Site%20Id%20%26amp%3B%20Web%20Id.%3C%2FP%3E%3CP%3EI%20want%20to%20find%20out%20web%20id%20of%20list%20of%20site%20collections.%20Above%20code%20gives%20me%20Title%20of%20web(site%20Collection)%20but%20fails%20for%20Web%20ID.%3C%2FP%3E%3CP%3EI%20hope%20it%20is%20clear.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107374%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107374%22%20slang%3D%22en-US%22%3E%3CP%3EFaced%20similar%20issue%20in%20the%20past%2C%20just%20initially%20%24web%20with%20null%20as%20below%20and%20check.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3Eforeach%20(%24row%20in%20%24data)%0A%7B%0AConnect-PnPOnline%20-Url%20%24row.Url%20-Credentials%20%24creds%0A%24web%3DGet-PnPWeb%0Awrite-host%20%22web%3A%20%22%20%2B%20%24web.Title%0Awrite-host%20%22web%3A%20%22%20%2B%20%24web.id%0A%24web%3D%24null%0A%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-107357%22%20slang%3D%22en-US%22%3ERe%3A%20Site%20Collection%3A%20Get%20Web%20Id%20fails%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-107357%22%20slang%3D%22en-US%22%3E%3CP%3EGet-PnPWeb%20gets%20the%20web%20within%20the%20current%20site.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20want%20to%20use%26nbsp%3BGet-PnPSubWebs%20to%20get%20all%20subwebs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethen%20select%20the%20one%20that%20you%20want%20by%3C%2FP%3E%3CP%3E%26nbsp%3BGet-PnPSubWebs%20%7C%20where%20%7B%20%24_.Title%20-eq%20%22sitetitle%22%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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

}

11 Replies
Highlighted

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"}

Highlighted

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
}

 

 

Highlighted

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.

Highlighted

Hi Narsima,

I have tried this already. No luck with this change.

 
Highlighted

Which version of PnP PowerShell are you using. I'm using the September release and Id is coming back without any problem.

Highlighted

I tried with September release. Still no luck. Are you providing list of site collections to the script? 

Highlighted

I opened 4-5 site collections in SharePoint Online Client Browser and they are showing same Web Id for all the site collections. In the screen shot below I am assuming Level 1 as Site Id and Level 2 as Web Id. Untitled.png

Highlighted

Are those site collections or sites?

 

I just ran this:

 

Connect-PnPOnline https://mytenant.sharepoint.com -Credentials $cred

Get-PnPWeb
 
Connect-PnPOnline https://mytenant.sharepoint.com/sites/site2 -Credentials $cred

Get-PnPWeb

Title                     ServerRelativeUrl Id                                  
-----                     ----------------- --                                  
My Team Site /                 e19d8f5e-d966-44f7-829b-c9cd39a2c462
Site 2                   /sites/site2    0b3bc433-e3f1-4415-9154-97b624a59189
Highlighted

These are site collections. Itried this:

Connect-PnPOnline https://mytenant.sharepoint.com/Sites/Site1 -Credentials $cred

Get-PnPWeb
 
Connect-PnPOnline https://mytenant.sharepoint.com/sites/site2 -Credentials $cred
Get-PnPWeb

and I get :

Title                  Id                                  
-----                  --------------------- --                                  
Site 1                 e19d8f5e-d966-44f7-829b-c9cd39a2c462
Site 2                 e19d8f5e-d966-44f7-829b-c9cd39a2c462

 


@Pieter Veenstra wrote:

Are those site collections or sites?

 

I just ran this:

 

Connect-PnPOnline https://mytenant.sharepoint.com -Credentials $cred

Get-PnPWeb
 
Connect-PnPOnline https://mytenant.sharepoint.com/sites/site2 -Credentials $cred

Get-PnPWeb

Title                     ServerRelativeUrl Id                                  
-----                     ----------------- --                                  
My Team Site /                 e19d8f5e-d966-44f7-829b-c9cd39a2c462
Site 2                   /sites/site2    0b3bc433-e3f1-4415-9154-97b624a59189

There are multiple site collections whhich has same Web Id. However Site Id is different for all the site collections. Also Sub Site's has unique ID's. This looks weird to me.

Highlighted

Do all you site collection have this problem?

 

the script below should list all your rootwebs

 

$cred = Get-Credential -Message "Password" -UserName admin@mytenant.onmicrosoft.com
Connect-PnPOnline https://mytenant.sharepoint.com -Credentials $cred

$sites = Get-PnPTenantSite 

foreach ($site in  $sites) { 
   Connect-PnPOnline $site.Url -Credentials $cred

   $web = Get-PnPWeb 
   $web
}
Highlighted

I can confirm that there are bunch of site collections which has same Web Id. 2 things i want to mention here: 1) we have created these(bulk) site collections using PowerShell

2) We are migrating data from SharePoint 2007 to these site collections.