Creating a Booking Delay on a Deployment Unit

Modified on Thu, 23 Nov 2023 at 07:28 PM

TABLE OF CONTENTS

Introduction

Most often within a project it might be useful to create a delay within the Self Schedule booking slot to prevent end users from booking a slot close to the Deployment Unit start day. 

This process will BLOCK slots in deployment units, essentially making them unavailable to end users when they are using the online booking process. For example by blocking the slots available in the next seven days, it means users will only be able to book 8 days out. The delay is configurable. This article will outline steps required to configure this within ManagementStudio.

Step 1 - Configure PowerShell

Now we need to add the PowerShell.

  • Switch to Administration->Deployment Units->PowerShell Scripts (1).
  • Click Click here to add new item (2).



  • Enter the following within the specified columns.


ColumnsDetails
Script NameBlock Slots Delay - It can be called anything
EnabledTicked
CategoryInternal - DU Block Slots Delay
DescriptionScript to block slots delay within a DU
Click Edit to edit the PowerShell scriptPaste in the below script.
ModuleDeployment Units
Run AsApi Account
Grant AccessApi Connectors


$config = Get-MSExtensionConfigData -ExtInstanceId $scriptArgs.CallerInput
$VarCount = ($config.misc.UserVars.count - 1)
$i = 0


$results = @()



Do{
$VarName = $config.misc.UserVars.variable[$i]
$VarValue = $config.misc.UserVars.Value[$i]
$i++
New-Variable -Name $Varname -Value $VarValue
Write-MSDebug -LogText "Variable $($VarName) = $($VarValue)`r`n"
}While ($i -le $VarCount)

$BlockBeforeDay = (Get-Date).AddDays($BookingDelay)
$Yesterday = (Get-Date).AddDays(-1)

# Search for Slots to block before day
ForEach($DU in $ScriptArgs.items){
        $slots = @()
        $slots = Get-MSDeployUnitMigrationSlots -DeployUnitId $DU  | Where-Object {$_.SlotsStartTime -le $BlockBeforeDay -and $_.SlotsStartTime -gt $Yesterday -and $_.FreeSlots -gt 0}

        $SlotsToBlock = @()

        foreach($slot in $slots){
            
                    $Count = 1
            
                    Do{
                    $SlotsToBlock += $Slot.SlotsStartTime
                    $Count += 1
                        } While($Count -le ([int64]$Slot.FreeSlots))

        
         }
            If(!$SlotsToBlock){
            $results += New-Object PSObject -Property @{
            InstanceId = $DU;
            ResultHeader = "No-Unused or Unblocked slots were available to be blocked";   
            ResultStatus = "Error";
                }
            Continue
            }
            
            Add-MSDeployUnitBlockedSlots -DeployUnitId $DU -BlockSlots $SlotsToBlock
            Write-MSDebug -LogText "Blocked a total of $($SlotsToBlock.Count) close Slots in DeploymentUnit `"$((Get-MSDeploymentUnits -DeployUnitIds $DU).DeployUnit)`" ID = $($DU)`r`n"
            $results += New-Object PSObject -Property @{
            InstanceId = $DU;
            ResultHeader = "$($SlotsToBlock.Count) Unused slots were blocked";   
            ResultStatus = "Success";
            }

}

$results 
  • Click Save Changes at the top of the screen.


Step 2 - Set up the ESM Plan

Create a new ESM plan in the DU section.

  • Switch to Administration->Extensions->Service Plans->Deployment Units (1). 
  • Click Service Plans (2).
  • Select New Service Plan (3).
  • Enter the name of the Plan (Block Slots Delay) and click OK.





  • Place a tick by Reset Prior to Run to ensure this plan runs every time for each DU.
  • The Evaluate phase should select all the DU's that should have the booking delay added.


  • The publish should call the PowerShell script created in step 1 above.


  • Scroll down to the bottom of the screen, there are Two Variables required
  • Click Save.



  • When the plan is ran, slots will be blocked.




Further Support

If you require further support, please visit ManagementStudio's Service Desk to search the knowledge base or create a new support ticket.