Provisioning Shifts (schedule) for a Microsoft Team via PowerShell

New Contributor

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 = "applicationhttps://techcommunity.microsoft.com/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 id

 

 

3 Replies

Hi @LauraFW 

 

you are getting error while excuting Update-MgTeamSchedule command.

try to run the below command share the update if it wont works.

Update-MgTeamSchedule -TeamId $tGroupId -Enabled $null

 

and setting for time zone please go through below links.

https://tahoeninjas.blog/2019/04/25/setting-the-default-timezone-for-sharepoint-online/

https://sharepoint.stackexchange.com/questions/264997/sharepoint-online-powershell-script-timezone-i...

@teams1535 I tried

Update-MgTeamSchedule -TeamId $tGroupId -Enabled $null

 

Error provisioning Shifts: A positional parameter cannot be found that accepts argument '$null'.

 

I see a -BodyParameter in the list of available parameters. Can I use that somehow?

Hi@LauraFW 

 

currently below 4 methods are available to do Update-MgTeamSchedule. Currently MS doc is not available in the link.

Please follow that link for the latest information. through powershell you will get more information (help update-mgteamschedule)command.

 

Update-MgTeamSchedule -TeamId <String> [-Enabled] [-Id <String>] [-OfferShiftRequests
<IMicrosoftGraphOfferShiftRequest[]>] [-OfferShiftRequestsEnabled] [-OpenShiftChangeRequests
<IMicrosoftGraphOpenShiftChangeRequest[]>] [-OpenShifts <IMicrosoftGraphOpenShift[]>] [-OpenShiftsEnabled]
[-ProvisionStatus <String>] [-ProvisionStatusCode <String>] [-SchedulingGroups <IMicrosoftGraphSchedulingGroup[]>]
[-Shifts <IMicrosoftGraphShift[]>] [-SwapShiftsChangeRequests <IMicrosoftGraphSwapShiftsChangeRequest[]>]
[-SwapShiftsRequestsEnabled] [-TimeClockEnabled] [-TimeOffReasons <IMicrosoftGraphTimeOffReason[]>]
[-TimeOffRequests <IMicrosoftGraphTimeOffRequest[]>] [-TimeOffRequestsEnabled] [-TimeZone <String>] [-TimesOff
<IMicrosoftGraphTimeOff[]>] [-WorkforceIntegrationIds <String[]>] [-Break] [-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>] [-PassThru] [-Proxy <Uri>] [-ProxyCredential <PSCredential>]
[-ProxyUseDefaultCredentials] [-WhatIf] [-Confirm] [<CommonParameters>]

Update-MgTeamSchedule -TeamId <String> -BodyParameter <IMicrosoftGraphSchedule> [-Break] [-HttpPipelineAppend
<SendAsyncStep[]>] [-HttpPipelinePrepend <SendAsyncStep[]>] [-PassThru] [-Proxy <Uri>] [-ProxyCredential
<PSCredential>] [-ProxyUseDefaultCredentials] [-WhatIf] [-Confirm] [<CommonParameters>]

Update-MgTeamSchedule -InputObject <ITeamsTeamIdentity> [-Enabled] [-Id <String>] [-OfferShiftRequests
<IMicrosoftGraphOfferShiftRequest[]>] [-OfferShiftRequestsEnabled] [-OpenShiftChangeRequests
<IMicrosoftGraphOpenShiftChangeRequest[]>] [-OpenShifts <IMicrosoftGraphOpenShift[]>] [-OpenShiftsEnabled]
[-ProvisionStatus <String>] [-ProvisionStatusCode <String>] [-SchedulingGroups <IMicrosoftGraphSchedulingGroup[]>]
[-Shifts <IMicrosoftGraphShift[]>] [-SwapShiftsChangeRequests <IMicrosoftGraphSwapShiftsChangeRequest[]>]
[-SwapShiftsRequestsEnabled] [-TimeClockEnabled] [-TimeOffReasons <IMicrosoftGraphTimeOffReason[]>]
[-TimeOffRequests <IMicrosoftGraphTimeOffRequest[]>] [-TimeOffRequestsEnabled] [-TimeZone <String>] [-TimesOff
<IMicrosoftGraphTimeOff[]>] [-WorkforceIntegrationIds <String[]>] [-Break] [-HttpPipelineAppend <SendAsyncStep[]>]
[-HttpPipelinePrepend <SendAsyncStep[]>] [-PassThru] [-Proxy <Uri>] [-ProxyCredential <PSCredential>]
[-ProxyUseDefaultCredentials] [-WhatIf] [-Confirm] [<CommonParameters>]

Update-MgTeamSchedule -InputObject <ITeamsTeamIdentity> -BodyParameter <IMicrosoftGraphSchedule> [-Break]
[-HttpPipelineAppend <SendAsyncStep[]>] [-HttpPipelinePrepend <SendAsyncStep[]>] [-PassThru] [-Proxy <Uri>]
[-ProxyCredential <PSCredential>] [-ProxyUseDefaultCredentials] [-WhatIf] [-Confirm] [<CommonParameters>]

www.000webhost.com