Get the Folder GUID using Power Shell

john john 941 Reputation points
2022-05-13T01:54:43.933+00:00

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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,628 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. CaseyYang-MSFT 10,321 Reputation points
    2022-05-13T08:08:56.153+00:00

    Hi @john john ,

    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.


  2. Limitless Technology 39,351 Reputation points
    2022-05-20T07:20:52.63+00:00

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

    0 comments No comments

  3. Craig Humphrey 16 Reputation points
    2023-03-26T21:03:07.4766667+00:00

    The property you are looking for is $Folder.UniqueId

    FYI using the standard SharePoint PowerShell commands (using a context, load and execute) can be constrained by throttling, you might be better off using the SharePoint PnP PowerShell and then use:

    $Folder= Get-PnPFolder -Url $ServerRelativeUrl -Includes UniqueId

    $Guid = $Folder.UniqueId

    Which is similar to @Limitless Technology 's solution, but less intensive, as it only pulls back the minimum of properties, but does include the GUID/Unique Id.

    0 comments No comments