Using New-MgBookingBusiness in Graph PowerShell

The New-MgBookingBusiness cmdlet in Microsoft Graph PowerShell is a powerful tool that allows administrators to create new bookings pages for businesses. Microsoft Bookings is an online scheduling tool that is integrated with Microsoft 365, enabling businesses to manage appointments and services. This cmdlet is particularly useful for automating the creation of business bookings pages in bulk, ensuring consistency and efficiency across multiple setups.


Cmdlet Syntax

New-MgBookingBusiness -BodyParameter <IMicrosoftGraphBookingBusiness>
  • -BodyParameter: This parameter is a hashtable that contains the properties of the booking business you want to create. The properties must be structured according to the conventions laid out in the Microsoft documentation.

Usage Examples

Example 1: Single Booking Business Creation

Creating a single business booking page is straightforward. The following example demonstrates how to create a new business booking page using the required properties:

$body = @{
    DisplayName = "Contoso Health Clinic"
    BusinessHours = @{
        Day = "Monday"
        StartTime = "08:00:00"
        EndTime = "17:00:00"
    }
    Address = @{
        Street = "123 Main St"
        City = "Redmond"
        State = "WA"
        PostalCode = "98052"
        CountryOrRegion = "US"
    }
    Phone = "+1 425-555-0100"
    Email = "contact@contosohealthclinic.com"
    WebSiteUrl = "https://contosohealthclinic.com"
}

New-MgBookingBusiness -BodyParameter $body

Example 2: Multiple Booking Businesses Creation

To create multiple business booking pages, you can loop through an array of hashtables, each representing a different business or service in your organization:

$businesses = @(
    @{
        DisplayName = "Contoso Health Clinic"
        BusinessHours = @{
            Day = "Monday"
            StartTime = "08:00:00"
            EndTime = "17:00:00"
        }
        Address = @{
            Street = "123 Main St"
            City = "Redmond"
            State = "WA"
            PostalCode = "98052"
            CountryOrRegion = "US"
        }
        Phone = "+1 425-555-0100"
        Email = "contact@contosohealthclinic.com"
        WebSiteUrl = "https://contosohealthclinic.com"
    }
    @{
        DisplayName = "Contoso Dental Clinic"
        BusinessHours = @{
            Day = "Tuesday"
            StartTime = "09:00:00"
            EndTime = "18:00:00"
        }
        Address = @{
            Street = "456 Second St"
            City = "Bellevue"
            State = "WA"
            PostalCode = "98007"
            CountryOrRegion = "US"
        }
        Phone = "+1 425-555-0200"
        Email = "contact@contosodentalclinic.com"
        WebSiteUrl = "https://contosodentalclinic.com"
    }
)

foreach ($business in $businesses) {
    New-MgBookingBusiness -BodyParameter $business
}

Example 3: Bulk Creation Using CSV

For bulk creation of business booking pages, you can use a CSV file to import data and then create new business booking pages based on the data.

CSV File Structure

This is how the CSV file must be structured with the relevant headers:

DisplayName,Day,StartTime,EndTime,Street,City,State,PostalCode,CountryOrRegion,Phone,Email,WebSiteUrl
Contoso Health Clinic,Monday,08:00:00,17:00:00,123 Main St,Redmond,WA,98052,US,+1 425-555-0100,contact@contosohealthclinic.com,https://contosohealthclinic.com
Contoso Dental Clinic,Tuesday,09:00:00,18:00:00,456 Second St,Bellevue,WA,98007,US,+1 425-555-0200,contact@contosodentalclinic.com,https://contosodentalclinic.com
Contoso Spa,Wednesday,10:00:00,19:00:00,789 Third St,Kirkland,WA,98033,US,+1 425-555-0300,contact@contosospaclub.com,https://contosospaclub.com
$csv = Import-Csv -Path "C:\BookingBusinesses.csv"

foreach ($row in $csv) {
    $body = @{
        DisplayName = $row.DisplayName
        BusinessHours = @{
            Day = $row.Day
            StartTime = $row.StartTime
            EndTime = $row.EndTime
        }
        Address = @{
            Street = $row.Street
            City = $row.City
            State = $row.State
            PostalCode = $row.PostalCode
            CountryOrRegion = $row.CountryOrRegion
        }
        Phone = $row.Phone
        Email = $row.Email
        WebSiteUrl = $row.WebSiteUrl
    }

    New-MgBookingBusiness -BodyParameter $body
}

Cmdlet Tips

  • Adhere to Property Conventions: When constructing the -BodyParameter hashtable, ensure that all properties adhere to the conventions specified in the Microsoft documentation. Incorrect property names or formats will result in errors.
  • Use Verbose for Debugging: If you encounter issues, run the cmdlet with the -Verbose parameter to get detailed output. This can help identify where the cmdlet is failing.
  • Validate Data: Before running the cmdlet, validate the data in your hashtables or CSV files to ensure it meets the required format and standards.

Possible Errors & Solutions

Error: "InvalidProperty"

Cause: This error occurs when a property in the -BodyParameter hashtable does not match the required format or is not recognized.

Solution: Double-check the property names and formats against the Microsoft documentation. Ensure that all required properties are included and correctly formatted.

Error: "BadRequest"

Cause: This error generally occurs when the provided data does not meet the API requirements.

Solution: Validate all input data, especially fields like email addresses, URLs, and phone numbers. Ensure they follow the required formats.

Error: "Unauthorized"

Cause: This error occurs if the account used to run the cmdlet does not have the necessary permissions to create Booking businesses.

Solution: Ensure the account has the required permissions. You may need to delegate permissions or use a different account with the appropriate access. Bookings.Read or Bookings.ReadWrite.All is the required Graph API permission.


Use Cases

  • Automated Setup for New Branches: When a business expands and opens new branches, you can use this cmdlet to automate the creation of Booking businesses for each new location. This ensures consistency and saves time compared to manual creation.
  • Migration from Legacy Systems: If you're migrating from a legacy appointment scheduling system to Microsoft Bookings, you can use the bulk creation method to quickly set up multiple Booking businesses, reducing downtime and ensuring a smooth transition.
  • Centralized Management of Multiple Businesses: For organizations managing multiple businesses or franchises, this cmdlet allows centralized and automated management of Booking setups, ensuring that all businesses are created with uniform settings.

Conclusion

The New-MgBookingBusiness cmdlet is an essential tool for administrators managing Microsoft Bookings in Microsoft 365. Whether you're setting up a single Booking business or automating the creation of multiple businesses across different locations, this cmdlet provides the flexibility and power needed to streamline the process. By adhering to the conventions outlined in the Microsoft documentation and following best practices, you can avoid common pitfalls and effectively utilize this cmdlet in your day-to-day operations.


Additional Resources:

How to Create Bookings Page Using Bookings App in Microsoft 365
Graph PowerShell New-MgBookingBusiness Cmdlet Documentation
Microsoft Graph PowerShell Module Documentation
Microsoft Graph API Documentation

Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex