Brug PowerShell til at forbinde Skift til Blue Yonder Workforce Management

Oversigt

Brug Microsoft Teams Shifts-connectoren til Blue Yonder til at integrere Appen Shifts i Microsoft Teams med Blue Yonder-Workforce Management (Blue Yonder WFM). Dine frontlinjemedarbejdere kan uden problemer få vist og administrere deres tidsplaner i Blue Yonder WFM fra Skift.

I denne artikel gennemgår vi, hvordan du bruger PowerShell til at konfigurere connectoren til at integrere Shifts med Blue Yonder WFM.

Hvis du vil konfigurere forbindelsen, skal du køre et PowerShell-script. Scriptet konfigurerer connectoren, anvender synkroniseringsindstillinger, opretter forbindelsen og knytter Blue Yonder WFM forekomster til teams. Synkroniseringsindstillinger bestemmer de funktioner, der er aktiveret i Skift, og de tidsplanoplysninger, der synkroniseres mellem Blue Yonder WFM og Shifts. Tilknytninger definerer synkroniseringsrelationen mellem dine Blue Yonder-WFM instanser og teams i Teams. Du kan knytte til eksisterende teams og nye teams.

Vi leverer to scripts. Du kan bruge begge scripts, afhængigt af om du vil knytte til eksisterende teams eller oprette nye teams, der skal tilknyttes.

Du kan konfigurere flere forbindelser, der hver især har forskellige synkroniseringsindstillinger. Hvis din organisation f.eks. har flere placeringer med forskellige tidsplankrav, skal du oprette en forbindelse med entydige synkroniseringsindstillinger for hver placering. Vær opmærksom på, at en Blue Yonder-WFM instans kun kan knyttes til ét team på et givent tidspunkt. Hvis en forekomst allerede er knyttet til et team, kan den ikke knyttes til et andet team.

Med Blue Yonder-WFM som postsystem kan dine frontlinjemedarbejdere administrere deres tidsplaner og tilgængelighed effektivt i Skift på deres enheder. Frontlineledere kan fortsætte med at bruge Blue Yonder WFM til at oprette tidsplaner.

Bemærk!

Du kan også bruge guiden Skifts-connector i Microsoft 365 Administration til at forbinde Shifts med blåt WFM.

Før du begynder

Forudsætninger

Før du kommer i gang, skal du sørge for at opfylde alle følgende forudsætninger:

  • Du har Blue Yonder WFM version 2020.3, 2021.1 eller 2021.2.

    Bemærk!

    Hvis du har Blue Yonder WFM 2020.3 eller 2021.1, skal du anvende programrettelsen 2020.3.0.4 eller 2021.1.0.3. Denne programrettelse løser et problem, hvor brugerne får en vedvarende fejlmeddelelse i Skift. Det løser også et problem, der forhindrer brugerne i at opdatere deres tilgængelighed i skift.

  • Du kender dine Blue Yonder WFM tjenestekontonavn, adgangskode og tjeneste-URL-adresser:

    • URL-adresse til godkendelse i organisationsnetværk
    • URL-adresse til cookiegodkendelse
    • URL-adresse til medarbejderselvbetjening
    • URL-adresse til detailweb-API
    • URL-adresse til WEBSTEDsstyring
    • URL-adresse til administrations-API

    Hvis du ikke har alle disse oplysninger, skal du kontakte Blue Yonder-support. En Blue Yonder-konto oprettes på rodvirksomhedsniveau af en Blue Yonder-virksomhedsadministrator. Den skal have adgang til API, klient Administration, Butiksstyring og Arbejder. Kontoen og adgangskoden kræves for at oprette en forbindelse.

  • SSO-godkendelse i organisationsnetværket er aktiveret i dit Blue Yonder WFM-miljø. Kontakt Blue Yonder-support for at sikre, at SSO i organisationsnetværket er aktiveret. De skal bruge følgende oplysninger:

    • federatedSSOValidationService: https://wfmconnector.teams.microsoft.com/api/v1/fedauth/{tenantId}/6A51B888-FF44-4FEA-82E1-839401E9CD74/authorize hvor {tenantId} er dit tenantId
    • proxyHeader: X-MS-AuthToken
  • Du har mindst ét team konfigureret i Teams.

  • Du har tilføjet en generel konto, det, vi kalder Microsoft 365-systemkontoen, som teamejer for alle de teams, du vil tilknytte.

    Opret denne konto i Microsoft 365 Administration, og tildel den en Microsoft 365-licens. Føj derefter kontoen som teamejer til alle de teams, du vil tilknytte. Shifts-connectoren bruger denne konto, når Skift-ændringer synkroniseres fra Blue Yonder WFM. Vi anbefaler, at du opretter en konto specifikt til dette formål og ikke bruger din personlige brugerkonto.

Administration rolle til at administrere connectoren ved hjælp af PowerShell

Du skal være global Administrator af Microsoft 365 eller Administrator af Skifts-connector for at fuldføre trinnene i denne artikel.

Rollen Shifts-connectoradministrator er en brugerdefineret rolle, som du opretter i Microsoft Entra id og tildeler til en bruger. Navnet på rollen skal være "Skifts connector-administrator". Rollen behøver ikke at have specifikke tilladelser, selvom der skal angives mindst én tilladelse, når du opretter den. Tjenesten er afhængig af tilstedeværelsen af rollen på brugeren og ikke dens tilladelser.

Du kan få mere at vide under Opret og tildel en brugerdefineret rolle i Microsoft Entra-id og Tildel Microsoft Entra roller til brugere. Vær opmærksom på, at det kan tage op til 24 timer, før rollen oprettes og anvendes på en bruger.

Konfigurer dit miljø

  1. Installér PowerShell version 7 eller nyere. Du kan finde en trinvis vejledning under Installation af PowerShell på Windows.

  2. Kør PowerShell i administratortilstand.

  3. Installér Microsoft Graph PowerShell-modulet.

    Install-Module Microsoft.Graph
    Import-Module Microsoft.Graph
    

    Kontrollér, at det er version 1.6.1 eller nyere.

    Get-InstalledModule Microsoft.Graph 
    
  4. Installér Teams Preview PowerShell-modulet.

    Install-Module -Name MicrosoftTeams -AllowPrerelease -Force
    Import-Module MicrosoftTeams 
    

    Kontrollér, at den er mindst version 4.7.0 og indeholder Shifts-connector-cmdlet'erne.

    Get-Command -Module MicrosoftTeams -Name *teamsshiftsconnection* 
    
  5. Indstil PowerShell til at afslutte, hvis der opstår en fejl, når scriptet køres.

    $ErrorActionPreference = "Stop" 
    
  6. Aktivér scripts til at køre i Windows.

    Set-ExecutionPolicy bypass 
    

Opret forbindelse til Teams

Kør følgende for at oprette forbindelse til Teams.

Connect-MicrosoftTeams

Når du bliver bedt om det, skal du logge på med dine administratorlegitimationsoplysninger. Du er nu konfigureret til at køre scripts i denne artikel og Shifts-connector-cmdlet'er.

Identificer de teams, du vil tilknytte

Bemærk!

Fuldfør dette trin, hvis du knytter Blue Yonder WFM forekomster til eksisterende teams. Hvis du opretter nye teams, der skal tilknyttes, kan du springe dette trin over.

I Azure Portal skal du gå til siden Alle grupper for at få vist en liste over TeamId'er for teams i din organisation.

Notér TeamId'erne for de teams, du vil tilknytte. Scriptet beder dig om at angive disse oplysninger.

Bemærk!

Hvis et eller flere teams har en eksisterende tidsplan, fjerner scriptet tidsplanerne fra disse teams. Ellers kan du se dublerede skift.

Kør scriptet

Kør et af følgende scripts, afhængigt af om du opretter et nyt team eller knytter til et eksisterende team:

  • Hvis du vil oprette en forbindelse, oprette et nyt team i Teams og knytte en Blue Yonder-forekomst WFM til det nye team, skal du køre scriptet for de nye teams.
  • Hvis du vil konfigurere en forbindelse og knytte Blue Yonder WFM forekomster til eksisterende teams i Teams, skal du køre scriptet for eksisterende teams.

Følg vejledningen på skærmen, når du kører scriptet. Scriptet fuldfører følgende handlinger:

  1. Test og bekræft forbindelsen til Blue Yonder WFM ved hjælp af legitimationsoplysningerne for blue yonder-WFM-tjenestekontoen og de tjeneste-URL-adresser, du angiver.

  2. Anvend synkroniseringsindstillinger. Disse indstillinger omfatter synkroniseringshyppigheden (i minutter) og de tidsplandata, der synkroniseres mellem Blue Yonder WFM og Skift. Du kan aktivere tidsplandata, der defineres af disse scenarier: Shift, SwapRequest, UserShiftPreferences, OpenShift, OpenShiftRequest, TimeOff, TimeOffRequest.

    Du kan få mere at vide under New-CsTeamsShiftsConnectionInstance. Hvis du vil se en liste over understøttede synkroniseringsindstillinger for hver parameter, skal du køre Get-CsTeamsShiftsConnectionConnector.

    Bemærk!

    Scriptet aktiverer synkronisering for hver understøttet synkroniseringsindstilling. Hvis du vil ændre synkroniseringsindstillingerne, kan du gøre det, når forbindelsen er oprettet. Du kan få mere at vide under Brug PowerShell til at administrere din Skift-forbindelse til Blue Yonder Workforce Management.

  3. Map Blue Yonder WFM forekomster til dine teams i Teams.

    • Hvis du vælger at køre scriptet for nye teams for at oprette nye teams, er tilknytninger baseret på de nye teams, du opretter.
    • Hvis du vælger at køre det eksisterende teamsscript for at tilknytte eksisterende teams, er tilknytninger baseret på de blå yonder-forekomst-id'er og TeamId'er, du angiver. Hvis et team har en eksisterende tidsplan, fjerner scriptet alle tidsplandata.

Når du har kørt scriptet, bekræfter en meddelelse om, at forbindelsen er oprettet.

Administrer din forbindelse

Når en forbindelse er konfigureret, kan du administrere og foretage ændringer af den i Microsoft 365 Administration eller ved hjælp af PowerShell.

Brug Microsoft 365 Administration

På siden Connectorstyring vises hver forbindelse, du har konfigureret, sammen med oplysninger som f.eks. tilstandsstatus og oplysninger om synkroniseringsintervaller. Du kan også få adgang til guiden for at foretage ændringer af dine forbindelser. Du kan f.eks. opdatere synkroniseringsindstillinger og teamtilknytninger.

Du kan få mere at vide under Brug Microsoft 365 Administration til at administrere din Skift-forbindelse til blue yonder-Workforce Management.

Brug PowerShell

Du kan bruge PowerShell til at få vist en fejlrapport, ændre forbindelsesindstillinger, deaktivere synkronisering og meget mere. Du kan finde en trinvis vejledning under Brug PowerShell til at administrere din Skift-forbindelse til Blue Yonder-Workforce Management.

Scripts

Konfigurer en forbindelse, og opret et nyt team

#Map WFM sites to teams script
Write-Output "Map WFM sites to teams"
Start-Sleep 1

#Ensure Teams module is at least version x
Write-Output "Checking Teams module version"
try {
	Get-InstalledModule -Name "MicrosoftTeams" -MinimumVersion 5.2.0
} catch {
	throw
}

#Connect to MS Graph
Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"

#List connector types available (comment out if not implemented for preview)
Write-Output "Listing connector types available"
$BlueYonderId = "6A51B888-FF44-4FEA-82E1-839401E9CD74"
$connectors = Get-CsTeamsShiftsConnectionConnector
Write-Output $connectors

#Prompt for entering of WFM username and password
$WfmUserName = Read-Host -Prompt 'Input your Blue Yonder account username'
$WfmPwd = Read-Host -Prompt 'Input your Blue Yonder account password' -AsSecureString
$plainPwd =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($WfmPwd))

#Test connection settings
Write-Output "Testing connection settings"
$ConnectionName = Read-Host -Prompt 'Input connection name'
$adminApiUrl = Read-Host -Prompt 'Input admin api url'
$cookieAuthUrl = Read-Host -Prompt 'Input cookie authorization url'
$essApiUrl = Read-Host -Prompt 'Input ess api url'
$federatedAuthUrl = Read-Host -Prompt 'Input federated authorization url'
$retailWebApiUrl = Read-Host -Prompt 'Input retail web api url'
$siteManagerUrl = Read-Host -Prompt 'Input site manager url'

$testResult = Test-CsTeamsShiftsConnectionValidate `
	-Name $ConnectionName `
	-ConnectorId $BlueYonderId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificBlueYonderSettingsRequest `
        -Property @{
            AdminApiUrl = $adminApiUrl
            SiteManagerUrl = $siteManagerUrl
            EssApiUrl = $essApiUrl
            RetailWebApiUrl = $retailWebApiUrl
            CookieAuthUrl = $cookieAuthUrl
            FederatedAuthUrl = $federatedAuthUrl
            LoginUserName = $WfmUserName
            LoginPwd = $plainPwd
        })
if ($NULL -ne $testResult.Code) {
	Write-Output $testResult
	throw "Validation failed, conflict found"
}
Write-Output "Test complete, no conflicts found"

#Create a connection
Write-Output "Creating a connection"
$ConnectionResponse = New-CsTeamsShiftsConnection `
    -Name $ConnectionName `
    -ConnectorId $BlueYonderId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificBlueYonderSettingsRequest `
		-Property @{
			AdminApiUrl = $adminApiUrl
			SiteManagerUrl = $siteManagerUrl
			EssApiUrl = $essApiUrl
			RetailWebApiUrl = $retailWebApiUrl
			CookieAuthUrl = $cookieAuthUrl
			FederatedAuthUrl = $federatedAuthUrl
			LoginUserName = $WfmUserName
			LoginPwd = $plainPwd
		})

$ConnectionId = $ConnectionResponse.Id
if ($null -ne $ConnectionId){
	Write-Output "Successfully created connection"
} else {
	throw "Connection creation failed"
}

#Create a connection instance
Write-Output "Creating a connection instance"
$designatedActorName = Read-Host -Prompt "Input Microsoft 365 System Account (person@contoso.com)"
$designator = Get-MgUser -UserId $designatedActorName
$teamsUserId = $designator.Id
$syncFreq = Read-Host -Prompt "Input sync frequency in minutes"
$InstanceName = Read-Host -Prompt "Input connection instance name"

#Read sync scenarios for connection instance
function GetSyncScenarioSetting {
	param (
		$SettingName
	)
	$TwoWay = New-Object System.Management.Automation.Host.ChoiceDescription '&TwoWay', 'TwoWay'
	$Disabled = New-Object System.Management.Automation.Host.ChoiceDescription '&Disabled', 'Disabled'
	$FromWfmToShifts = New-Object System.Management.Automation.Host.ChoiceDescription '&FromWfmToShifts', 'FromWfmToShifts'
	$options = [System.Management.Automation.Host.ChoiceDescription[]]($TwoWay, $Disabled, $FromWfmToShifts)
	$result = $host.ui.PromptForChoice("Set sync scenario for $SettingName", "", $options, 0)

	switch ($result)
	{
		0 { return "TwoWay" }
		1 { return "Disabled" }
		2 { return "FromWfmToShifts" }
	}
}
$SyncScenarioOpenShift = GetSyncScenarioSetting "Open Shift"
$SyncScenarioOpenShiftRequest = GetSyncScenarioSetting "Open Shift Request"
$SyncScenarioShift = GetSyncScenarioSetting "Shift"
$SyncScenarioSwapRequest = GetSyncScenarioSetting "Swap Request"
$SyncScenarioTimeCard = GetSyncScenarioSetting "Time Card"
$SyncScenarioTimeOff = GetSyncScenarioSetting "Time Off"
$SyncScenarioTimeOffRequest = GetSyncScenarioSetting "Time Off Request"
$SyncScenarioUserShiftPreference = GetSyncScenarioSetting "User Shift Preferences"

#Read admin email list
[psobject[]]$AdminEmailList = @()
while ($true){
	$AdminEmail = Read-Host -Prompt "Enter admin's email to receive error report"
	$AdminEmailList += $AdminEmail
	$title    = 'Adding another email'
	$question = 'Would you like to add another admin email?'
	$choices  = '&Yes', '&No'
	$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
	if ($decision -eq 1) {
		break
	}
}
$InstanceResponse = New-CsTeamsShiftsConnectionInstance `
	-ConnectionId $ConnectionId `
    -ConnectorAdminEmail $AdminEmailList `
    -DesignatedActorId $teamsUserId `
    -Name $InstanceName `
    -SyncFrequencyInMin $syncFreq `
	-SyncScenarioOpenShift $SyncScenarioOpenShift `
	-SyncScenarioOpenShiftRequest $SyncScenarioOpenShiftRequest `
	-SyncScenarioShift $SyncScenarioShift `
	-SyncScenarioSwapRequest $SyncScenarioSwapRequest `
	-SyncScenarioTimeCard $SyncScenarioTimeCard `
	-SyncScenarioTimeOff $SyncScenarioTimeOff `
	-SyncScenarioTimeOffRequest $SyncScenarioTimeOffRequest `
	-SyncScenarioUserShiftPreference $SyncScenarioUserShiftPreference

$InstanceId = $InstanceResponse.id
if ($null -ne $InstanceId){
    Write-Output "Success"
} else {
    throw "Connector instance creation failed"
}

#Keep mapping teams until user stops it
$mappings=@()
while ($true)
{
	#Create a new Teams team with owner set to system account and name set to the site name
	Write-Output "Creating a Teams team"
	$teamsTeamName = Read-Host -Prompt "Input the Teams team name"
	$Team = New-Team -DisplayName $teamsTeamName -Visibility "Public" -Owner $teamsUserId
	Write-Output "Successfully created a team"
	$TeamsTeamId=$Team.GroupId

	#Retrieve the list of wfm locations
	Write-Output "Listing the WFM team sites"
	$WfmTeamIds = Get-CsTeamsShiftsConnectionWfmTeam -ConnectorInstanceId $InstanceId
	Write-Output $WfmTeamIds
	if (($NULL -ne $WfmTeamIds) -and ($WfmTeamIds.Count -gt 0)){
		[System.String]$WfmTeamId = Read-Host -Prompt "Input the ID of WFM team you want to map"
	}
	else {
		throw "The WfmTeamId list is null or empty"
	}

	#Retrieve the list of WFM users and their roles
	Write-Output "Listing WFM users and roles"
	$WFMUsers = Get-CsTeamsShiftsConnectionWfmUser -ConnectorInstanceId $InstanceId -WfmTeamId $WfmTeamId
	Write-Output $WFMUsers

	#Add users to the Team for Shifts
	Write-Output "Adding users to Teams team"
	$currentUser = Read-Host -Prompt "Input the current user's user name or AAD ID"
	Add-TeamUser -GroupId $TeamsTeamId -User $currentUser -Role Owner
	$failedWfmUsers=@()
	foreach ($user in $WFMUsers) {
		try {
		$userEmail = $user.Name + "@" +$domain
		Add-TeamUser -GroupId $TeamsTeamId -User $userEmail
		} catch {
			$failedWfmUsers+=$user
		}
	}
	if($failedWfmUsers.Count -gt 0){
		Write-Output "There are WFM users not existed in Teams tenant:"
		Write-Output $failedWfmUsers
	}

	#Enable scheduling in the group
	$RequestBody = @{
		Enabled = $true
		TimeZone = "America/Los_Angeles"
	}
	$teamUpdateUrl="https://graph.microsoft.com/v1.0/teams/"+$TeamsTeamId+"/schedule"
	Invoke-MgGraphRequest -Uri $teamUpdateUrl -Method PUT -Body $RequestBody

	#Create a mapping of the new team to the instance
	Write-Output "Create a mapping of the new team to the site"
	$TimeZone = Read-Host -Prompt "Input the time zone of team mapping"
	$mapping = @{
		teamId = $TeamsTeamId
		wfmTeamId = $WfmTeamId
		timeZone = $TimeZone
		}
	$mappings += , $mapping

	$title    = 'Connecting another team'
	$question = 'Would you like to connect another team?'
	$choices  = '&Yes', '&No'

	$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
	if ($decision -eq 1) {
		break
	}
}
$batchMappingResponse = New-CsTeamsShiftsConnectionBatchTeamMap -ConnectorInstanceId $InstanceId -TeamMapping @($mappings)
if ($null -ne $batchMappingResponse.OperationId){
	"The mapping has begun asynchronously. To query mapping results run Get-CsTeamsShiftsConnectionOperation with the operation Id."
}
else {
	throw "The mapping has failed due to validation errors."
}
Write-Output $batchMappingResponse

Remove-TeamUser -GroupId $TeamsTeamId -User $currentUser -Role Owner
Disconnect-MgGraph

Konfigurer en forbindelse, og tilknyt et eksisterende team

#Map WFM sites to existing teams script
Write-Output "Map WFM sites to existing teams"
Start-Sleep 1

#Ensure Teams module is at least version x
Write-Output "Checking Teams module version"
try {
	Get-InstalledModule -Name "MicrosoftTeams" -MinimumVersion 5.2.0
} catch {
	throw
}

#Connect to MS Graph
Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"

#List connector types available (comment out if not implemented for preview)
Write-Output "Listing connector types available"
$BlueYonderId = "6A51B888-FF44-4FEA-82E1-839401E9CD74"
$connectors = Get-CsTeamsShiftsConnectionConnector
Write-Output $connectors

#Prompt for entering of WFM username and password
$WfmUserName = Read-Host -Prompt 'Input your Blue Yonder account username'
$WfmPwd = Read-Host -Prompt 'Input your Blue Yonder account password' -AsSecureString
$plainPwd =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($WfmPwd))

#Test connection settings
Write-Output "Testing connection settings"
$ConnectionName = Read-Host -Prompt 'Input connection name'
$adminApiUrl = Read-Host -Prompt 'Input admin api url'
$cookieAuthUrl = Read-Host -Prompt 'Input cookie authorization url'
$essApiUrl = Read-Host -Prompt 'Input ess api url'
$federatedAuthUrl = Read-Host -Prompt 'Input federated authorization url'
$retailWebApiUrl = Read-Host -Prompt 'Input retail web api url'
$siteManagerUrl = Read-Host -Prompt 'Input site manager url'

$testResult = Test-CsTeamsShiftsConnectionValidate `
	-Name $ConnectionName `
	-ConnectorId $BlueYonderId `
	-ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificBlueYonderSettingsRequest `
		-Property @{
			AdminApiUrl = $adminApiUrl
			SiteManagerUrl = $siteManagerUrl
			EssApiUrl = $essApiUrl
			RetailWebApiUrl = $retailWebApiUrl
			CookieAuthUrl = $cookieAuthUrl
			FederatedAuthUrl = $federatedAuthUrl
			LoginUserName = $WfmUserName
			LoginPwd = $plainPwd
		})
		
if ($NULL -ne $testResult.Code) {
	Write-Output $testResult
	throw "Validation failed, conflict found"
}
Write-Host "Test complete, no conflicts found"

#Create a connection
Write-Output "Creating a connection"
$ConnectionResponse = New-CsTeamsShiftsConnection `
    -Name $ConnectionName `
    -ConnectorId $BlueYonderId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificBlueYonderSettingsRequest `
		-Property @{
			AdminApiUrl = $adminApiUrl
			SiteManagerUrl = $siteManagerUrl
			EssApiUrl = $essApiUrl
			RetailWebApiUrl = $retailWebApiUrl
			CookieAuthUrl = $cookieAuthUrl
			FederatedAuthUrl = $federatedAuthUrl
			LoginUserName = $WfmUserName
			LoginPwd = $plainPwd
		})

$ConnectionId = $ConnectionResponse.Id
if ($null -ne $ConnectionId){
	Write-Output "Successfully created connection"
} else {
	throw "Connection creation failed"
}

#Create a connection instance
Write-Output "Creating a connection instance"
$designatedActorName = Read-Host -Prompt "Input Microsoft 365 System Account (person@contoso.com)"
$designator = Get-MgUser -UserId $designatedActorName
$teamsUserId = $designator.Id
$syncFreq = Read-Host -Prompt "Input sync frequency in minutes"
$InstanceName = Read-Host -Prompt "Input connection instance name"

#Read sync scenarios for connection instance
function GetSyncScenarioSetting {
	param (
		$SettingName
	)
	$TwoWay = New-Object System.Management.Automation.Host.ChoiceDescription '&TwoWay', 'TwoWay'
	$Disabled = New-Object System.Management.Automation.Host.ChoiceDescription '&Disabled', 'Disabled'
	$FromWfmToShifts = New-Object System.Management.Automation.Host.ChoiceDescription '&FromWfmToShifts', 'FromWfmToShifts'
	$options = [System.Management.Automation.Host.ChoiceDescription[]]($TwoWay, $Disabled, $FromWfmToShifts)
	$result = $host.ui.PromptForChoice("Set sync scenario for $SettingName", "", $options, 0)

	switch ($result)
	{
		0 { return "TwoWay" }
		1 { return "Disabled" }
		2 { return "FromWfmToShifts" }
	}
}
$SyncScenarioOpenShift = GetSyncScenarioSetting "Open Shift"
$SyncScenarioOpenShiftRequest = GetSyncScenarioSetting "Open Shift Request"
$SyncScenarioShift = GetSyncScenarioSetting "Shift"
$SyncScenarioSwapRequest = GetSyncScenarioSetting "Swap Request"
$SyncScenarioTimeCard = GetSyncScenarioSetting "Time Card"
$SyncScenarioTimeOff = GetSyncScenarioSetting "Time Off"
$SyncScenarioTimeOffRequest = GetSyncScenarioSetting "Time Off Request"
$SyncScenarioUserShiftPreference = GetSyncScenarioSetting "User Shift Preferences"

#Read admin email list
[psobject[]]$AdminEmailList = @()
while ($true){
	$AdminEmail = Read-Host -Prompt "Enter admin's email to receive error report"
	$AdminEmailList += $AdminEmail
	$title    = 'Adding another email'
	$question = 'Would you like to add another admin email?'
	$choices  = '&Yes', '&No'
	$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
	if ($decision -eq 1) {
		break
	}
}
$InstanceResponse = New-CsTeamsShiftsConnectionInstance `
	-ConnectionId $ConnectionId `
    -ConnectorAdminEmail $AdminEmailList `
    -DesignatedActorId $teamsUserId `
    -Name $InstanceName `
    -SyncFrequencyInMin $syncFreq `
	-SyncScenarioOpenShift $SyncScenarioOpenShift `
	-SyncScenarioOpenShiftRequest $SyncScenarioOpenShiftRequest `
	-SyncScenarioShift $SyncScenarioShift `
	-SyncScenarioSwapRequest $SyncScenarioSwapRequest `
	-SyncScenarioTimeCard $SyncScenarioTimeCard `
	-SyncScenarioTimeOff $SyncScenarioTimeOff `
	-SyncScenarioTimeOffRequest $SyncScenarioTimeOffRequest `
	-SyncScenarioUserShiftPreference $SyncScenarioUserShiftPreference

$InstanceId = $InstanceResponse.id
if ($null -ne $InstanceId){
    Write-Output "Success"
} else {
    throw "Connector instance creation failed"
}

#Keep mapping teams until user stops it
$mappings=@()
while ($true)
{
	$TeamsTeamId = Read-Host -Prompt "Input the ID of the Teams team to be mapped"
	#Clear schedule of the Teams team
	Write-Host "Clear schedule of the existing team"

	$entityTypeString = Read-Host -Prompt 'Input the entity types of clear schedule'
	$Delimiters = ",", ".", ":", ";", " ", "`t"
	$entityType = $entityTypeString -Split {$Delimiters -contains $_}
	$entityType = $entityType.Trim()
	$entityType = $entityType.Split('',[System.StringSplitOptions]::RemoveEmptyEntries)
	Remove-CsTeamsShiftsScheduleRecord -TeamId $TeamsTeamId -ClearSchedulingGroup:$True -EntityType $entityType

	#Retrieve the list of wfm locations
	Write-Output "Listing the WFM team sites"
	$WfmTeamIds = Get-CsTeamsShiftsConnectionWfmTeam -ConnectorInstanceId $InstanceId
	Write-Output $WfmTeamIds
	if (($NULL -ne $WfmTeamIds) -and ($WfmTeamIds.Count -gt 0)){
		[System.String]$WfmTeamId = Read-Host -Prompt "Input the ID of WFM team you want to map"
	}
	else {
		throw "The WfmTeamId list is null or empty"
	}

	#Retrieve the list of WFM users and their roles
	Write-Output "Listing WFM users and roles"
	$WFMUsers = Get-CsTeamsShiftsConnectionWfmUser -ConnectorInstanceId $InstanceId -WfmTeamId $WfmTeamId
	Write-Output $WFMUsers

	#Create a mapping of the existing team to the instance
	Write-Host "Create a mapping of the existing team to the site"
	$TimeZone = Read-Host -Prompt "Input the time zone of team mapping"
	$mapping = @{
		teamId = $TeamsTeamId
		wfmTeamId = $WfmTeamId
		timeZone = $TimeZone
		}
	$mappings += , $mapping

	$title    = 'Connecting another team'
	$question = 'Would you like to connect another team?'
	$choices  = '&Yes', '&No'

	$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
	if ($decision -eq 1) {
		break
	}
}
$batchMappingResponse = New-CsTeamsShiftsConnectionBatchTeamMap -ConnectorInstanceId $InstanceId -TeamMapping @($mappings)
if ($null -ne $batchMappingResponse.OperationId){
	"The mapping has begun asynchronously. To query mapping results run Get-CsTeamsShiftsConnectionOperation with the operation Id."
}
else {
	throw "The mapping has failed due to validation errors."
}
Write-Output $batchMappingResponse

Disconnect-MgGraph

Skifter forbindelses-cmdlet'er

Hvis du vil have hjælp til Shifts-connector-cmdlet'er, herunder de cmdlet'er, der bruges i scripts, skal du søge efter CsTeamsShiftsConnection i Reference til Teams PowerShell-cmdlet'en. Her er links til nogle almindeligt anvendte cmdlet'er grupperet efter kategori:

Forbindelser

legitimationsoplysninger til WFM systemer

Synkroniseringsindstillinger for understøttede scenarier

Fjern plandata

Forbindelsesforekomster

Brugertilknytning og vellykket synkronisering

Gruppetilknytning

Handlings-id

Fejlrapporter