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.
New-MgBookingBusinessCustomer -BookingBusinessId <String> -BodyParameter <PSObject>
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
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
}
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.
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
}
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.
Cause: The address property does not follow the required structure.
Solution: Structure the address property correctly as shown in the usage examples.
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.
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.
© m365corner.com. All Rights Reserved. Design by HTML Codex