Shifts in Microsoft Teams
2 TopicsCreating, getting and deleting Shifts using PowerShell
Hi, I am trying to prototype an interface for my organisation which can list, create and delete Shifts using PowerShell. The interface would take in data from a seperate application I cannot control, so I am restricted to using PowerShell. Is it only possible to do this by using appropriate MS Graph API calls and managing the associated permission scopes? Ideally if there was a way to do it directly through PowerShell this would be preferred. Any guidance or alternate methods on how I could go about designing this interface would be appreciated.1.7KViews0likes2CommentsProvisioning Shifts (schedule) for a Microsoft Team via PowerShell
Hi 🙂 I am trying to provision Shifts (schedule) for Teams. The overall script creates a new Team, then passes the ID to the shifts piece. But I cannot, for the life of me, find a way to provision it. Here's my code (using a hard coded ID till I figure out what's up.) Ultimately, this will be part of a script that creates several Teams, each needing to have Shifts enabled. Where I start # THIS IS WHERE I'M STUCK # in my code, trying to work with the "Enabled" parameter, I have tried to use $true, 1, nothing, "yes". Nothing works. If I don't leave the space null after -Enabled, I get an error "Update-MgTeamSchedule : A positional parameter cannot be found that accepts argument 'True'" (or whatever notnull value I put there.) If I leave the space after -Enabled null, I get "Update-MgTeamSchedule : [UnknownError] : At line:1 char:1 + Update-MgTeamSchedule -TeamId e532aa85-3ec5-4318-9515-6c60cfaa7f36 -E ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ({ TeamId = e532...GraphSchedule }:<>f__AnonymousType0`2) [Update-MgTeamSchedule_UpdateExpanded], Exception + FullyQualifiedErrorId : UnknownError,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgTeamSchedule_UpdateExpanded" AND - how should the TimeZone be formatted for New York? "American/NewYork" or "American/New York" (with or without a space). Any help would be greatly appreciated. 🙂 🙂 (I am not a PS pro obviously, but I am a super enthusiast.) TIA! function EnableShifts { param ( [parameter( HelpMessage = "Group ID" )] [string] $tGroupId ) process { #Import-Module -Name MicrosoftTeams Connect-MicrosoftTeams -Credential $cred # Let's make sure it's getting the ID Write-Host "Group ID:" $tGroupId <# company/app info #> $AppId = "xx" $AppSecret = 'xx' $TenantId = "xx" #$TenantName = "xx" #$TenantShortName = "xx" # Construct URI and body needed for authentication $uri = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token" $body = @{ client_id = $AppId scope = "https://graph.microsoft.com/.default" client_secret = $AppSecret grant_type = "client_credentials" } # Get OAuth 2.0 Token $tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing # Unpack Access Token $token = ($tokenRequest.Content | ConvertFrom-Json).access_token $headers = @{Authorization = "Bearer $token" } $ctype = "application/json" # check out the Team output Get-Team -GroupId $tGroupId $uriPath = "https://graph.microsoft.com/v1.0/teams/$tGroupId" # Connect to graph to use the graph powershell modules Connect-Graph -Scopes Schedule.ReadWrite.All -TenantId $TenantId try { # see what this command returns Get-MgTeamSchedule -TeamId $tGroupId # THIS IS WHERE I'M STUCK # Update-MgTeamSchedule -TeamId $tGroupId -Enabled $true #Invoke-WebRequest -Method Put -Uri "$uriPath/schedule" -ContentType $ctype -Headers $headers # | ConvertTo-Json Write-Host "Shifts provisioned" } catch { Write-Host "Error provisioning Shifts:" $Error -BackgroundColor yellow -ForegroundColor black break } finally { } } } #for testing. comment out to use the CreateTeams_Search.CSV EnableShifts -tGroupId "xxx" #Team id5KViews0likes3Comments