Del via


Bruk PowerShell til å koble skift til UKG Pro Workforce Management

Oversikt

Bruk Microsoft Teams Shifts-koblingen for UKG Pro Workforce Management til å integrere Skift-appen i Microsoft Teams med UKG Pro Workforce Management (UKG Pro WFM). Dine frontline arbeidere kan sømløst se og administrere sine tidsplaner i UKG Pro WFM fra innsiden Skift.

I denne artikkelen veileder vi deg gjennom hvordan du bruker PowerShell til å konfigurere koblingen til å integrere skift med UKG Pro-WFM.

Hvis du vil konfigurere tilkoblingen, kjører du et PowerShell-skript. Skriptet konfigurerer koblingen, bruker synkroniseringsinnstillinger, oppretter tilkoblingen og tilordner UKG Pro WFM forekomster (også kalt WFM forekomster) til team i Teams. Synkroniseringsinnstillingene bestemmer hvilke funksjoner som er aktivert i Skift, og tidsplaninformasjonen som synkroniseres mellom UKG Pro WFM og Skift. Tilordninger definerer synkroniseringsrelasjonen mellom WFM forekomster og team i Teams. Du kan tilordne til eksisterende team og nye team.

Vi gir to skript. Du kan bruke enten skript, avhengig av om du vil tilordne til eksisterende team eller opprette nye team å tilordne til.

Du kan konfigurere flere tilkoblinger, hver med ulike synkroniseringsinnstillinger. Hvis organisasjonen for eksempel har flere plasseringer med ulike tidsplankrav, kan du opprette en tilkobling med unike synkroniseringsinnstillinger for hver plassering. Husk at en WFM forekomst bare kan tilordnes til ett team til enhver tid. Hvis en forekomst allerede er tilordnet til et team, kan den ikke tilordnes til et annet team.

Med UKG Pro WFM som det registrerte systemet, kan frontlinjearbeiderne effektivt administrere sine tidsplaner og tilgjengelighet i Skift på enhetene sine. Frontline-ledere kan fortsette å bruke UKG Pro WFM til å sette opp tidsplaner.

Obs!

Du kan også bruke skiftkoblingsveiviseren i Administrasjonssenter for Microsoft 365 til å koble skift til UKG Pro-WFM.

Før du starter

Forutsetninger

Ta deg tid til å se gjennom informasjonen og fullføre alle forutsetninger og konfigurasjonsoppgaver i forutsetninger og krav for Teams Shifts-koblingen for UKG Pro-Workforce Management.

Kontroller at du fullfører alle oppgavene før du følger trinnene i denne artikkelen.

Admin rolle for å administrere koblingen ved hjelp av PowerShell

Du må være en global Microsoft 365-administrator eller en Shifts-koblingsadministrator for å fullføre trinnene i denne artikkelen.

Administratorrollen for Shifts-koblingen er en egendefinert rolle som du oppretter i Microsoft Entra ID og tilordner til en bruker. Navnet på rollen må være Skiftkoblingsadministrator. Rollen trenger ikke å ha bestemte tillatelser, men minst én tillatelse må angis når du oppretter den. Tjenesten er avhengig av tilstedeværelsen av rollen på brukeren, og ikke dens tillatelser.

Hvis du vil ha mer informasjon, kan du se Opprette og tilordne en egendefinert rolle i Microsoft Entra ID og tilordne Microsoft Entra roller til brukere. Husk at det kan ta opptil 24 timer før rollen opprettes og brukes på en bruker.

Konfigurer miljøet ditt

  1. Installer PowerShell versjon 7 eller nyere. Hvis du vil ha trinnvis veiledning, kan du se Installere PowerShell på Windows.

  2. Kjør PowerShell i administratormodus.

  3. Installer Microsoft Graph PowerShell-modulen.

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

    Kontroller at det er versjon 1.6.1 eller nyere.

    Get-InstalledModule Microsoft.Graph 
    
  4. Installer Teams Preview PowerShell-modulen.

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

    Kontroller at det er minst versjon 4.7.0 og inneholder Shifts-koblings-cmdleter.

    Get-Command -Module MicrosoftTeams -Name *teamsshiftsconnection* 
    
  5. Angi at PowerShell skal avsluttes hvis det oppstår en feil når skriptet kjøres.

    $ErrorActionPreference = "Stop" 
    
  6. Aktiver skript som skal kjøres i Windows.

    Set-ExecutionPolicy bypass 
    

Koble til Teams

Kjør følgende for å koble til Microsoft Teams.

Connect-MicrosoftTeams

Når du blir bedt om det, logger du på med administratorlegitimasjonen. Du er nå konfigurert til å kjøre skriptene i denne artikkelen og Shifts-koblings-cmdleter.

Identifiser teamene du vil tilordne

Obs!

Fullfør dette trinnet hvis du tilordner WFM forekomster til eksisterende team. Hvis du oppretter nye team å tilordne til, kan du hoppe over dette trinnet.

Gå til Alle grupper-siden i Azure Portal for å få en liste over TeamIds for team i organisasjonen.

Noter team-ID-ene for teamene du vil tilordne. Skriptet vil be deg om å angi denne informasjonen.

Obs!

Hvis ett eller flere team har en eksisterende tidsplan, vil skriptet fjerne tidsplanene fra disse teamene. Ellers ser du dupliserte skift.

Kjør skriptet

Kjør ett av følgende skript, avhengig av om du oppretter et nytt team eller tilordner til et eksisterende team:

  • Hvis du vil konfigurere en tilkobling, oppretter du et nytt team i Teams og tilordner en WFM forekomst til det nye teamet, kjører du det nye teams-skriptet.
  • Hvis du vil konfigurere en tilkobling og tilordne WFM forekomster til eksisterende team i Teams, kjører du det eksisterende teams-skriptet.

Følg instruksjonene på skjermen når du kjører skriptet. Skriptet fullfører følgende handlinger:

  1. Test og kontroller tilkoblingen til UKG Pro WFM ved hjelp av ukg pro-WFM tjenestekontolegitimasjon og url-adresser for tjeneste som du angir.

  2. Bruk synkroniseringsinnstillinger. Disse innstillingene inkluderer synkroniseringsfrekvensen (i minutter) og tidsplandataene som synkroniseres mellom UKG Pro WFM og Skift. Du kan aktivere tidsplandata som er definert av disse scenariene: Shift, , SwapRequest, UserShiftPreferencesOfferShiftRequest, OpenShift, OpenShiftRequest, TimeOffTimeOffRequest.

    Hvis du vil ha mer informasjon, kan du se New-CsTeamsShiftsConnectionInstance. Hvis du vil se listen over støttede synkroniseringsalternativer for hver parameter, kjører du Get-CsTeamsShiftsConnectionConnector.

    Obs!

    Skriptet aktiverer synkronisering for hvert synkroniseringsalternativ som støttes. Hvis du vil endre synkroniseringsinnstillingene, kan du gjøre dette etter at tilkoblingen er konfigurert. Hvis du vil ha mer informasjon, kan du se Bruke PowerShell til å administrere Shifts-tilkoblingen til UKG Pro Workforce Management.

  3. Tilordne WFM forekomster til teamene dine i Teams.

    • Hvis du velger å kjøre det nye teams-skriptet for å opprette nye team, er tilordninger basert på de nye teamene du oppretter.
    • Hvis du velger å kjøre det eksisterende teams-skriptet for å kartlegge eksisterende team, er tilordninger basert på WFM forekomst-ID-er og TeamId-er du angir. Hvis et team har en eksisterende tidsplan, fjerner skriptet alle tidsplandata.

Når du har kjørt skriptet, bekrefter en vellykket melding om tilkoblingen er konfigurert.

Administrer tilkoblingen

Når en tilkobling er konfigurert, kan du administrere og gjøre endringer i den i Administrasjonssenter for Microsoft 365 eller ved hjelp av PowerShell.

Bruk Administrasjonssenter for Microsoft 365

Siden for koblingsbehandling viser hver tilkobling du har konfigurert, sammen med informasjon som tilstandsstatus og detaljer om synkroniseringsintervall. Du kan også få tilgang til veiviseren for å gjøre endringer i noen av tilkoblingene. Du kan for eksempel oppdatere synkroniseringsinnstillinger og teamtilordninger.

Hvis du vil ha mer informasjon, kan du se Bruke Administrasjonssenter for Microsoft 365 til å administrere Shifts-tilkoblingen til UKG Pro-Workforce Management.

Bruk PowerShell

Du kan bruke PowerShell til å vise en feilrapport, endre tilkoblingsinnstillinger, deaktivere synkronisering og mer. Hvis du vil ha trinnvis veiledning, kan du se Bruke PowerShell til å administrere Shifts-tilkoblingen til UKG Pro-Workforce Management.

Skript

Konfigurere en tilkobling og opprette et nytt team

#Map WFM instances 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
Write-Output "Listing connector types available"
$UkgId = "95BF2848-2DDA-4425-B0EE-D62AEED4C0A0"
$connectors = Get-CsTeamsShiftsConnectionConnector
Write-Output $connectors
$Ukg = $connectors | Where-Object {$_.Id -match $UkgId}
if ($NULL -eq $Ukg) {
    throw "UKG Dimensions not currently supported"
}

#Prompt for entering of WFM username and password
$WfmUserName = Read-Host -Prompt 'Input your UKG account username'
$WfmPwd = Read-Host -Prompt 'Input your UKG 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'
$apiUrl = Read-Host -Prompt 'Input connector api url'
$ssoUrl = Read-Host -Prompt 'Input connector sso url'
$clientId = Read-Host -Prompt 'Input connector client id'
$AppKey = Read-Host -Prompt 'Input your app key' -AsSecureString
$plainKey =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($AppKey))
$ClientSecret = Read-Host -Prompt 'Input your client secret' -AsSecureString
$plainSecret =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($ClientSecret))

$testResult = Test-CsTeamsShiftsConnectionValidate `
    -Name $ConnectionName `
    -ConnectorId $UkgId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificUkgDimensionsSettingsRequest `
        -Property @{
            apiUrl = $apiUrl
            ssoUrl = $ssoUrl
            appKey = $plainKey
            clientId = $clientId
            clientSecret = $plainSecret
            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 $UkgId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificUkgDimensionsSettingsRequest `
        -Property @{
            apiUrl = $apiUrl
            ssoUrl = $ssoUrl
            appKey = $plainKey
            clientId = $clientId
            clientSecret = $plainSecret
            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" }
    }
}
$SyncScenarioOfferShiftRequest = GetSyncScenarioSetting "Offer Shift Request"
$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 `
    -SyncScenarioOfferShiftRequest $SyncScenarioOfferShiftRequest `
    -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

Konfigurere en tilkobling og tilordne et eksisterende team

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

#Ensure Teams module is at least version x
Write-Host "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
Write-Output "Listing connector types available"
$UkgId = "95BF2848-2DDA-4425-B0EE-D62AEED4C0A0"
$connectors = Get-CsTeamsShiftsConnectionConnector
Write-Output $connectors
$Ukg = $connectors | Where-Object {$_.Id -match $UkgId}
if ($NULL -eq $Ukg) {
    throw "UKG Dimensions not currently supported"
}

#Prompt for entering of WFM username and password
$WfmUserName = Read-Host -Prompt 'Input your UKG account username'
$WfmPwd = Read-Host -Prompt 'Input your UKG 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'
$apiUrl = Read-Host -Prompt 'Input connector api url'
$ssoUrl = Read-Host -Prompt 'Input connector sso url'
$clientId = Read-Host -Prompt 'Input connector client id'
$AppKey = Read-Host -Prompt 'Input your app key' -AsSecureString
$plainKey =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($AppKey))
$ClientSecret = Read-Host -Prompt 'Input your client secret' -AsSecureString
$plainSecret =[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($ClientSecret))

$testResult = Test-CsTeamsShiftsConnectionValidate `
    -Name $ConnectionName `
    -ConnectorId $UkgId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificUkgDimensionsSettingsRequest `
        -Property @{
            apiUrl = $apiUrl
            ssoUrl = $ssoUrl
            appKey = $plainKey
            clientId = $clientId
            clientSecret = $plainSecret
            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 $UkgId `
    -ConnectorSpecificSettings (New-Object Microsoft.Teams.ConfigAPI.Cmdlets.Generated.Models.ConnectorSpecificUkgDimensionsSettingsRequest `
        -Property @{
            apiUrl = $apiUrl
            ssoUrl = $ssoUrl
            appKey = $plainKey
            clientId = $clientId
            clientSecret = $plainSecret
            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" }
    }
}
$SyncScenarioOfferShiftRequest = GetSyncScenarioSetting "Offer Shift Request"
$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 `
    -SyncScenarioOfferShiftRequest $SyncScenarioOfferShiftRequest `
    -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

Skiftkoblings-cmdleter

Hvis du trenger hjelp med Cmdleter for Shifts-koblinger, inkludert cmdleter som brukes i skriptene, kan du søke etter CsTeamsShiftsConnection i Cmdlet-referansen for Teams PowerShell. Her er koblinger til noen ofte brukte cmdleter, gruppert etter kategori:

Connections

legitimasjon for WFM systemer

Synkroniseringsalternativer for støttede scenarioer

Fjern tidsplandata

Tilkoblingsforekomster

Brukertilordning og vellykket synkronisering

Gruppetilordning

Operasjons-ID

Feilrapporter