Using New-MgBookingBusinessCustomer in Graph PowerShell

The New-MgBookingBusinessCustomer cmdlet is part of the Microsoft Graph PowerShell module, enabling administrators to create new customers for a specific booking business. This cmdlet is essential for businesses utilizing Microsoft Bookings, as it automates customer management and enhances the efficiency of booking operations.


Note: You need Business ID to work with this cmdlet. Use Get-MgBookingBusiness to get the required business id.


Cmdlet Syntax

New-MgBookingBusinessCustomer -BookingBusinessId <String> -BodyParameter <PSObject>
  • -BookingBusinessId <String>: Specifies the ID of the booking business where the customer is to be created.
  • -BodyParameter <PSObject>: Contains the customer details to be created, passed as a hashtable. This parameter includes properties such as DisplayName, EmailAddress, Phone, etc.

Usage Examples

Example 1: Create a Single Customer

In this example, a single customer named John Doe is created with basic contact details. The address property is structured following the required format, ensuring no errors during execution:

$customerDetails = @{
    displayName = "John Doe"
    emailAddress = "john.doe@example.com"
    phone = "+1234567890"
    address = @{
        street = "123 Main St"
        city = "Metropolis"
        state = "NY"
        postalCode = "10001"
        countryOrRegion = "US"
    }
}

New-MgBookingBusinessCustomer -BookingBusinessId "business-id" -BodyParameter $customerDetails

Example 2: Create Multiple Customers

This script demonstrates creating multiple customers by iterating over an array of hashtables, each representing a different customer. This approach is useful for adding several customers in one go:

$customers = @(
    @{
        displayName = "Jane Smith"
        emailAddress = "jane.smith@example.com"
        phone = "+0987654321"
        address = @{
            street = "456 Broadway"
            city = "Gotham"
            state = "NY"
            postalCode = "10002"
            countryOrRegion = "US"
        }
    }
    @{
        displayName = "Bob Brown"
        emailAddress = "bob.brown@example.com"
        phone = "+1122334455"
        address = @{
            street = "789 Park Ave"
            city = "Central City"
            state = "CA"
            postalCode = "90001"
            countryOrRegion = "US"
        }
    }
)

foreach ($customer in $customers) {
    New-MgBookingBusinessCustomer -BookingBusinessId "business-id" -BodyParameter $customer
}

Example 3: Bulk Customer Import Using CSV

This example demonstrates bulk importing customers from a CSV file. Each row in the CSV corresponds to a customer, with the script reading the data and creating customers in the specified booking business.

CSV File Structure

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

DisplayName,EmailAddress,Phone,Street,City,State,PostalCode,CountryOrRegion
John Doe,john.doe@example.com,+1234567890,123 Main St,Metropolis,NY,10001,US
Jane Smith,jane.smith@example.com,+0987654321,456 Broadway,Gotham,NY,10002,US
Bob Brown,bob.brown@example.com,+1122334455,789 Park Ave,Central City,CA,90001,US
$csvData = Import-Csv -Path "C:\Path\To\Customers.csv"

foreach ($row in $csvData) {
    $customerDetails = @{
        displayName = $row.DisplayName
        emailAddress = $row.EmailAddress
        phone = $row.Phone
        address = @{
            street = $row.Street
            city = $row.City
            state = $row.State
            postalCode = $row.PostalCode
            countryOrRegion = $row.CountryOrRegion
        }
    }

    New-MgBookingBusinessCustomer -BookingBusinessId "business-id" -BodyParameter $customerDetails
}

Cmdlet Tips

  • Accurate Address Formatting: Ensure the address property in the hashtable follows the correct structure to avoid errors.
  • Using CSV for Bulk Import: CSV import is ideal for onboarding multiple customers at once. Make sure the CSV headers match the properties required by the cmdlet.
  • Error Handling: Implement error handling when processing multiple customers to identify and correct issues with specific entries.

Possible Errors & Solutions

Error: "Invalid request: Missing required property 'DisplayName'"

Cause: The DisplayName property is not provided in the -BodyParameter hashtable.

Solution: Ensure the DisplayName property is included in the hashtable when creating a customer.

Error: "Invalid address format"

Cause: The address property does not follow the required structure.

Solution: Structure the address property correctly as shown in the usage examples.

Error: "Unauthorized"

Cause: The script lacks the necessary permissions to create customers in the booking business.

Solution: Verify that the user running the script has sufficient permissions to perform this action. Bookings.ReadWrite.All is the required Graph API permission.


Use Cases

  • Automated Customer Management: For businesses that regularly add new customers to their booking system, automating the process through PowerShell can save significant time and reduce manual errors.
  • Bulk Onboarding for Events: When preparing for large events where multiple customers need to be added to the booking system, the bulk import capability using CSV is invaluable.
  • System Integration: Businesses with existing CRM systems can use this cmdlet to integrate customer data into Microsoft Bookings, ensuring all customer interactions are centralized.

Conclusion

The New-MgBookingBusinessCustomer cmdlet is a powerful tool for managing customers within Microsoft Bookings. Whether adding a single customer, multiple customers, or importing them in bulk from a CSV file, this cmdlet offers flexibility and efficiency. By following the correct syntax and ensuring proper formatting of properties, administrators can avoid common errors and streamline their customer management processes.

With the rise of automation and integration in business operations, mastering cmdlets like New-MgBookingBusinessCustomer is essential for IT professionals aiming to enhance their organization's productivity.


Additional Resources:

Graph PowerShell New-MgBookingBusinessCustomer 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