Forum Discussion
New-MgBookingBusinessService | Turn Customer Information Questions Off
I'm trying to turn off the stock Customer information questions except for customer email but cannot find how to do it? Any support is much appreciated. Below is what I've recently tried...
# Prompt for Booking Business ID
$bookingBusinessId = Read-Host "Enter the Booking Business ID (e.g., email address removed for privacy reasons)"
# Prompt for default duration in minutes
$defaultDurationMinutes = Read-Host "Enter default appointment duration in minutes (e.g., 15)"
$defaultDuration = [TimeSpan]::FromMinutes([double]$defaultDurationMinutes)
# Post-buffer stays at 5 minutes
$postBuffer = [TimeSpan]::FromMinutes(5)
# Hardcoded Excel file path
$excelFilePath = "C:\Users\apettit\OneDrive - Eau Claire Area School District\Downloads\adamtestconferencedata.xlsx"
# Prompt for worksheet/tab name
$sheetName = Read-Host "Enter the worksheet/tab name to read data from"
# Import Excel data using Import-Excel (requires ImportExcel module)
if (-not (Get-Module -ListAvailable -Name ImportExcel)) {
Install-Module -Name ImportExcel -Scope CurrentUser -Force
}
Import-Module ImportExcel
$staffEmails = Import-Excel -Path $excelFilePath -WorksheetName $sheetName
# Retrieve all staff members for the booking business
Write-Host "Fetching all staff members for booking business ID: $bookingBusinessId"
$allStaff = Get-MgBookingBusinessStaffMember -BookingBusinessId $bookingBusinessId
if (-not $allStaff) {
Write-Error "No staff members found for the booking business ID: $bookingBusinessId"
return
}
# Retrieve all custom questions
Write-Host "Fetching all custom questions for booking business ID: $bookingBusinessId"
$allCustomQuestions = Get-MgBookingBusinessCustomQuestion -BookingBusinessId $bookingBusinessId
if (-not $allCustomQuestions) {
Write-Error "No custom questions found for the booking business ID: $bookingBusinessId"
return
}
# Loop through each staff member from Excel automatically
Write-Host "Creating individual booking services for each staff member..."
foreach ($row in $staffEmails) {
$email = $row.emailAddress.Trim().ToLower()
# Automatically match staff from Booking Business
$matchingStaff = $allStaff | Where-Object {
$_.AdditionalProperties["emailAddress"] -and ($_.AdditionalProperties["emailAddress"].Trim().ToLower() -eq $email)
}
if ($matchingStaff) {
$staffId = $matchingStaff.Id
$displayName = $matchingStaff.AdditionalProperties["displayName"]
Write-Host "Automatically creating service for: ${displayName} ($email)" -ForegroundColor Cyan
try {
# Prepare custom questions
$customQuestions = $allCustomQuestions | ForEach-Object -Begin { $isLast = $false } -Process {
$isLast = ($_.Id -eq $allCustomQuestions[-1].Id)
$questionAssignment = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphBookingQuestionAssignment
$questionAssignment.QuestionId = $_.Id
$questionAssignment.IsRequired = if ($isLast) { $false } else { $true }
$questionAssignment
}
# Prepare the reminder
$defaultReminder = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphBookingReminder
$defaultReminder.Message = "Don't forget! Family Teacher Conferences are tomorrow, and we are excited to visit with you! If you wish to change the meeting type (virtual, in-person, hybrid, or phone), please let the teacher know as soon as possible!"
$defaultReminder.Offset = [TimeSpan]::FromDays(1)
$defaultReminder.Recipients = @("customer")
# Prepare service parameters
$serviceParams = @{
BookingBusinessId = $bookingBusinessId
DisplayName = "${displayName} Family Conference"
Description = "Family Teacher Conference with ${displayName}"
StaffMemberIds = @($staffId) # Assign specific staff member
DefaultDuration = $defaultDuration
DefaultPrice = 0.00
DefaultPriceType = "free"
CustomQuestions = $customQuestions
PostBuffer = $postBuffer
IsLocationOnline = $true
IsCustomerAllowedToManageBooking = $true
DefaultReminder = $defaultReminder
AdditionalInformation = @"
Please arrive on time for your conferences as we will be sticking to a tight schedule.
If you wish to change the meeting type (virtual, in-person, hybrid, or phone), please let the teacher know as soon as possible.
If you require a translator, please submit a request at this form: https://forms.office.com/r/
"@ # Appears in the customer confirmation email
}
# Log service parameters
Write-Host "Service Parameters for ${displayName}:" -ForegroundColor Blue
$serviceParams.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" }
# Create the booking service
New-MgBookingBusinessService @serviceParams
Write-Host "Booking service successfully created for ${displayName}!" -ForegroundColor Green
} catch {
Write-Error "Failed to create booking service for ${displayName}: $_"
}
} else {
Write-Warning "No match found for email: $email"
}
}
2 Replies
- LainRobertsonSilver Contributor
Hi AP_TC_ECASD,
I don't use these APIs, but looking at the documentation, Graph shows that bookingBusiness and bookingCustomQuestion are two separate endpoints. The bookingBusiness endpoint documentation even lists customQuestions as a relationship (read-only, at that) rather than a property.
What this collectively points to is that you cannot create the businessBooking entity and the bookingCustomQuestion with a single call to New-MgBookingBusinessService. Rather, you will need to:
- Call New-MgBookingBusiness first;
- Call New-MgBookingBusinessCustomQuestion afterwards, using the "id" obtained from the above commandlet. You'll need to call this once per question as it doesn't take multiple questions as input.
References:
- New-MgBookingBusiness (Microsoft.Graph.Bookings) | Microsoft Learn
- New-MgBookingBusinessCustomQuestion (Microsoft.Graph.Bookings) | Microsoft Learn
- bookingBusiness resource type - Microsoft Graph v1.0 | Microsoft Learn
- bookingCustomQuestion resource type - Microsoft Graph v1.0 | Microsoft Learn
- Create bookingCustomQuestion - Microsoft Graph v1.0 | Microsoft Learn
Cheers,
Lain
- AP_TC_ECASDBrass Contributor
LainRobertson Unfortunately, I don’t think that’s it. I create and control custom questions all the time and the Customer information questions aren’t a part of that module.