question

johnjohn-0472 avatar image
0 Votes"
johnjohn-0472 asked LimitlessTechnology-2700 answered

Get the Folder GUID using Power Shell

I am trying to get the folder GUID using its URL, i tried this power shell:-

 #Variables
 $SiteURL = "https://*****.sharepoint.com"
 $ServerRelativeUrl= "/Shared Documents/FolderA"
     
 Try {
    
     
     #Setup the context
     Connect-PnPOnline -Url https://******.sharepoint.com -UseWebLogin
     $Ctx =  Get-PnPContext
    
     #Get the web from URL
     $Web = $Ctx.web
     $Ctx.Load($Web)
     $Ctx.executeQuery()
     
     #Get the Folder object by Server Relative URL
     $Folder = $Web.GetFolderByServerRelativeUrl($ServerRelativeUrl)
     $Ctx.Load($Folder)
     $Ctx.ExecuteQuery() 
         
     #Get Some Folder Properties
     Write-host -f Green "Folder GUID:"$Folder.GUID
 }
 Catch {
     write-host -f Red "Error Getting Folder!" $_.Exception.Message
 }

but i did not get any result. any advice? Thanks

office-sharepoint-onlinewindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CaseyYangMSFT-4714 avatar image
0 Votes"
CaseyYangMSFT-4714 answered YiLu-MSFT commented

Hi @johnjohn-0472,

You could get folder GUID in folder url as a workaround.

201741-1.jpg


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



1.jpg (37.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @johnjohn-0472
Is this answer helpful for you? Please feel free to reply.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello,

You need to explicitly mention ListItemAllFields while loading folder:

$Folder = Get-PnPFolder -Url $ServerRelativeUrl -Includes ListItemAllFields
$folderGuid = $Folder.ListItemAllFields["GUID"]




--If the reply is helpful, please Upvote and Accept as answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.