Error when running Get-PnPTenantSite : The remote server returned an error: (403) Forbidden. Help

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3066350%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3EError%20when%20running%20Get-PnPTenantSite%20%3A%20The%20remote%20server%20returned%20an%20error%3A%20(403)%20Forbidden.%20Help%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3066350%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CP%3EHi%20All%2C%3CBR%20%2F%3EHopefully%20someone%20can%20help%20me%20here%3CBR%20%2F%3EI%20can't%20get%20to%20run%20the%20below%20via%20windows%20powershell%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%24Sites%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20%3D%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3EGet-PnPTenantSite%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-Filter%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22Url%20-like%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%24TenantURL%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20%7C%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3EWhere-Object%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20%7B%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%24_%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E.template%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-eq%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22OFFILE%231%22%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-or%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%24_%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E.template%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-eq%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22SITEPAGEPUBLISHING%230%22%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-or%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%24_%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E.template%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-eq%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22STS%230%22%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-or%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%24_%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E.template%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%20-eq%20%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%22STS%23-1%22%26lt%3B%5C%2FSPAN%26gt%3B%3CSPAN%3E%7D%26lt%3B%5C%2FSPAN%26gt%3B%26lt%3B%5C%2FDIV%26gt%3B%3CDIV%3E%26nbsp%3B%26lt%3B%5C%2FDIV%26gt%3B%3CDIV%3E%3CSPAN%3EI%20keep%20getting%20error%26lt%3B%5C%2FSPAN%26gt%3B%26lt%3B%5C%2FDIV%26gt%3B%3CDIV%3E%3CSTRONG%3EGet-PnPTenantSite%20%3A%20The%20remote%20server%20returned%20an%20error%3A%20(403)%20Forbidden%26lt%3B%5C%2FSTRONG%26gt%3B%26lt%3B%5C%2FDIV%26gt%3B%3CDIV%3EI%20can%20confirm%20I%20can%20use%20the%20same%20account%20to%20login%20to%20the%20admin%20center%20and%20i%20can%20view%20all%20the%20sites.%3CBR%20%2F%3E%3CBR%20%2F%3EAny%20recommendation%20on%20what%20could%20be%20wrong%20or%20what%20access%20level%20do%20i%20need%20to%20run%20this%20successfully%20and%20how%20can%20i%20confirm%20the%20acct%20i'm%20using%20to%20run%20this.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26lt%3B%5C%2FDIV%26gt%3B%3CDIV%3EThanks%20in%20Advance%26lt%3B%5C%2FDIV%26gt%3B%26lt%3B%5C%2FDIV%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3CLINGO-LABS%20id%3D%22%5C%26quot%3Blingo-labs-3066350%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CLINGO-LABEL%3EAzure%26lt%3B%5C%2Flingo-label%26gt%3B%3CLINGO-LABEL%3EDevOps%26lt%3B%5C%2Flingo-label%26gt%3B%26lt%3B%5C%2Flingo-labs%26gt%3B%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E
Frequent Contributor

Hi All,
Hopefully someone can help me here
I can't get to run the below via windows powershell

 

$Sites = Get-PnPTenantSite -Filter "Url -like $TenantURL" | Where-Object { $_.template -eq "OFFILE#1" -or $_.template -eq "SITEPAGEPUBLISHING#0" -or $_.template -eq "STS#0" -or $_.template -eq "STS#-1"}
 
I keep getting error
Get-PnPTenantSite : The remote server returned an error: (403) Forbidden
I can confirm I can use the same account to login to the admin center and i can view all the sites.

Any recommendation on what could be wrong or what access level do i need to run this successfully and how can i confirm the acct i'm using to run this.


Thanks in Advance
1 Reply

Hi @Patrick Rote,

 

I got same error. At the first time I tried with an older PnP Powershell module (3.22.2006.1), if the MFA was enabled on user. Without MFA Get-PnPTenantSite worked well. I have updated the pnp module to 3.29.2101.0. With the new version it works with MFA!

Thanks,
slotty