Forum Discussion

Mitch Crump's avatar
Mitch Crump
Copper Contributor
Feb 11, 2020

Get SharePoint Site URL of an individual Microsoft Team

I found the below code online. I want to use the same concept but only return one SP site URL so I can use the URL to create a folder in that Team.

$Teams = (Get-Team |Select GroupId, DisplayName)
ForEach ($T in $Teams) {
   $SPOURl = (Get-UnifiedGroup -Identity $T.GroupId | Select -ExpandProperty SharePointSiteURL)
   Write-Host "URL for the" $T.DisplayName "team is" $SPOURL }

 
It would be easiest to start with getting the Team by displayname then taking the group ID and using that. All the individual versions of -expandproperty SharePointURL have not worked for me yet. Any advice?

Get-Team -DisplayName $Team | Select GroupId

 

  • Might help if you give us the exact samples you are running, I don't see any problem with the above.

    • Mitch Crump's avatar
      Mitch Crump
      Copper Contributor

      VasilMichev I am trying to do something like the two examples below

      Get-Team -DisplayName $Team | Select GroupId
      $SPOURL = (Get-Team -Identity $Team.GroupId | Select -ExpandProperty SharePointSiteURL)

       

      Get-Team -DisplayName $Team | Select GroupId
      $SPOURL = (Get-PnpSite -Identity $Team.GroupId | Select -ExpandProperty SharePointSiteURL)
      • Mitch Crump's avatar
        Mitch Crump
        Copper Contributor

        Mitch Crump I don't want to use UnifiedGroup because I only want a singular URL but now Get-UnifiedGroup is not working for me and I can't find the required module to install for it.

         

        PS C:\WINDOWS\system32> Find-Module -Includes Cmdlet Get-UnifiedGroup
        PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'Get-UnifiedGroup'. Try Get-PSRepository to see all available registered module repositories.
        At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1397 char:3
        +         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
        +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
            + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

         

         
    • Tom__B's avatar
      Tom__B
      Copper Contributor
      The MailNickName of a team can be updated with PowerShell, thus the TeamURL no longer matches this schema `$TeamURL = "https://Name_of_Tenancy.sharepoint.com/sites/" + $teamMailNickName`.
      The SharePoint site URL of a Team can also be updated independently.
  • Tom__B's avatar
    Tom__B
    Copper Contributor

    Mitch Crump 

    With Graph Explorer, I'm able to request the following endpoint:

     

    GET https://graph.microsoft.com/v1.0/groups/{groupId}/sites/root?$select=name,webUrl

     

    Which return the requested information:

     

    {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(name,webUrl)/$entity",
    "name": "MYTEAMSITE",
    "webUrl": "https://<tenant>.sharepoint.com/sites/MYTEAMSITE"
    }

     

     

    But the translated PowerShell query doesn't work for me, it asks for a $SiteId parameter, but I don't know how to get it for a Team site:

     

    Import-Module Microsoft.Graph.Sites
    Get-MgGroupSite -GroupId $groupId -SiteId $siteId -Property "name,webUrl" 

     

     

    • Tom__B's avatar
      Tom__B
      Copper Contributor

      Instead of using a couple of PowerShell Modules (ExchangeOnlineManagement, MicrosoftTeams, Sharepoint online management shell), I managed to do what I wanted (Updating MailNickname and SharePointSiteURL of aTeams site) with PnP.Powershell module.

       

      With this module, to get a Teams Site URL, use the following code:

      Get-PnPMicrosoft365Group -Identity $GroupId -IncludeSiteUrl | Select-Object -ExpandProperty SiteUrl

       

Resources