Azure Data Services
6 TopicsNew-MgBookingBusinessService CustomQuestions
Hi! I'm working my way though BookingBusiness with PowerShell, so please forgive me if this is obvious. I've tried combing documentation but nothing seems to work. I have this script, and first, I think I have to create the customQuestions and have done so successfully and have the reference IDs for the questions to use in the New-MgBookingBusinessService script. I cannot seem to get the customQuestion piece to work. I'm first getting the available business staff and the custom questions I've already created. Everything works until I try the CustomQuestions piece. Here is what I have if you could please provide any assistance or guidance. Thank you! # Define the Booking Business ID $bookingBusinessId = "SCRUBBED" # Path to your CSV file $csvFilePath = "SCRUBBED" # Import CSV file $staffEmails = Import-Csv -Path $csvFilePath # Retrieve all staff members for the booking business Write-Host "Fetching all staff members for booking business ID: $bookingBusinessId" $allStaff = Get-MgBookingBusinessStaffMember -BookingBusinessId $bookingBusinessId # Ensure $allStaff is not null or empty if (-not $allStaff) { Write-Error "No staff members found for the booking business ID: $bookingBusinessId" return } # Debugging: Display all staff members retrieved (with Email and ID) Write-Host "Staff members retrieved (Email and ID):" -ForegroundColor Green $allStaff | ForEach-Object { $email = $_.AdditionalProperties["emailAddress"] $id = $_.Id $displayName = $_.AdditionalProperties["displayName"] Write-Host "DisplayName: $displayName, Email: $email, ID: $id" -ForegroundColor Yellow } # Retrieve all custom questions for the booking business Write-Host "Fetching all custom questions for booking business ID: $bookingBusinessId" $allCustomQuestions = Get-MgBookingBusinessCustomQuestion -BookingBusinessId $bookingBusinessId # Ensure $allCustomQuestions is not null or empty if (-not $allCustomQuestions) { Write-Error "No custom questions found for the booking business ID: $bookingBusinessId" return } # Debugging: Display all custom questions retrieved (with ID and DisplayName) Write-Host "Custom questions retrieved (ID and DisplayName):" -ForegroundColor Green $allCustomQuestions | ForEach-Object { $id = $_.Id $displayName = $_.DisplayName Write-Host "ID: $id, DisplayName: $displayName" -ForegroundColor Yellow } # Loop through each staff member in the CSV and create an individual service for them Write-Host "Creating individual booking services for each staff member..." $staffEmails | ForEach-Object { $email = $_.staffemail.Trim().ToLower() # Find the matching staff member by email $matchingStaff = $allStaff | Where-Object { $_.AdditionalProperties["emailAddress"] -and ($_.AdditionalProperties["emailAddress"].Trim().ToLower() -eq $email) } if ($matchingStaff) { $staffId = $matchingStaff.Id Write-Host "Match found: Email: $email -> ID: $staffId" -ForegroundColor Cyan # Create the booking service for the matched staff member try { $serviceParams = @{ BookingBusinessId = $bookingBusinessId DisplayName = "$($matchingStaff.AdditionalProperties["displayName"]) Family Conference" StaffMemberIds = @($staffId) # Create a service only for this staff member DefaultDuration = [TimeSpan]::FromHours(1) DefaultPrice = 50.00 DefaultPriceType = "free" Notes = "Please arrive 10 minutes early for your booking." CustomQuestions = $allCustomQuestions | ForEach-Object { @{ Id = $_.Id IsRequired = $true # or $false depending on your requirement } } } # Log the parameters being sent Write-Host "Service Parameters for $($matchingStaff.AdditionalProperties["displayName"]):" -ForegroundColor Blue $serviceParams.GetEnumerator() | ForEach-Object { Write-Host "$($_.Key): $($_.Value)" } New-MgBookingBusinessService @serviceParams Write-Host "Booking service successfully created for $($matchingStaff.AdditionalProperties["displayName"])!" -ForegroundColor Green } catch { Write-Error "Failed to create booking service for $($matchingStaff.AdditionalProperties["displayName"]): $_" } } else { Write-Warning "No match found for email: $email" } }92Views0likes8CommentsPowershell Script to extract Azure VM Metrics data
Hi Community, hope you are doing well. I am currently playing around with powershell scripting and trying to extract Azure VM utilization data using Get-AzMetric powershell module. I am trying to extract VM metrics through my script for all VMs in my current subscription (free trial) and outputting the same to a csv file. I can see the data getting extracted when I run in console but when I run the script I am unable to see the data getting outputted to my csv file. Please find below my script: # Modules importation #$modules = 'Az.Accounts','Az.Compute', 'Az.Reservations' , 'Az.Storage' , 'Az.Billing' ,'Az.BillingBenefits' ,'Az.Monitor','Az.ResourceGraph', 'Join-Object' ,'PSExcel' ,'Az.Resources', 'Az.CostManagement','ImportExcel' # PS Module required #Install-Module -Name $modules -Scope CurrentUser -Force #Powershell-5.1 # Suppress breaking changes Set-Item Env:\SuppressAzurePowerShellBreakingChangeWarnings "true" # Connect to Azure Connect-AzAccount # Name of the analyze [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') $title = ' Azure VM Usage' $msg = 'Please enter the name of the analyze:' $checklistname = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) # Subscription(s) selection - CTRL & click to select more than 1 subscription $subquery = (Get-AzSubscription | Out-GridView -Title "Select an Azure Subscription" -PassThru) $sub = $subquery.Id Write-Host "Subscription(s) selected: $sub" -ForegroundColor Green # Creation of the directroy New-Item -Path "c:\" -Name "Azurecost\$checklistname" -ItemType "directory" -force set-location c:\azurecost\$checklistname #$csvFileVM = New-Object System.IO.StreamWriter("c:\azurecost\$checklistname\VM-Usage.csv") #$csvFileVM.WriteLine("Name, Id, ResourceGroup, MaxCPU") foreach ($subscription in $sub) { # Set the subscription context Set-AzContext -Subscription $subscription $vms = Get-AzVM $vmUtilizationData = @() # Loop through each VM to get utilization metrics foreach ($vm in $vms) { $vmName = $vm.Name $resourceId = $vm.Id $Resourcegroup = $vm.ResourceGroupName # Get metrics for the VM (e.g., CPU Percentage) $metric = Get-AzMetric -ResourceId $resourceId -MetricName "Percentage CPU" -TimeGrain 12:00:00 -StartTime (Get-Date).AddDays(-3) -EndTime (Get-Date) $MaxCPU = $metric.data.maximum | Measure-Object -Maximum | Select-Object -property Maximum #$csvFileVM.WriteLine(" $MaxCPU") $vmUtilizationData += [PSCustomObject]@{ VMName = $vmName ResourceGroup = $Resourcegroup MaxCPU = $MaxCPU } } } $vmUtilizationData | Export-Csv -Path "c:\Azurecost\$checklistname\VMUsage.csv" -NoTypeInformation Write-Host "Your script has finished running." pause Please help me understand what am I missing here since other details like VM name, Resource group name are getting outputted to my csv file through this script except the metric values.284Views0likes0Commentspowershell: how to remove a calendar for many users?
Hi all, I've hundreds users and they should remove a calendar (having the same name for each user) from their outlook. No way to ask them to go into outlook doing right click - remove... Any chances to go through powershell commands?873Views0likes3CommentsInstall-Module MSOnline - not working
Hi all, I am struggling to install: Install-Module MSOnline I get: I have tried: Get-PSRepository WARNING: Unable to find module repositories. When I run: Register-PSRepository -Default I get no error but when trying to run Get-PSRepository again i get WARNING: Unable to find module repositories. Any ideas on how to fix this?Solved21KViews0likes1CommentRemove Metadata from MMD Column with Powershell
Trying to remove a managed metadata value from a file via Powershell - there are a lot of resources online discussing PnP Powershell and how to manipulate metadata, that is, set metadata, edit metadata, and also creating a column default value from term store metadata. However, I have the situation that I need to "remove" metadata, and leave the file's particular column with an "unassigned" state, not the word "Unassigned" of course, but just EMPTY. Which is considered, "unassigned". If you're interested in why I need this, it is because we wrote a powershell runbook that looks for moved files - then makes sure the metadata is correct. If the file was moved from a specific folder depth in the library to depth - 1, I have to set that deepest folder to "unassigned". Currently working with a terrible workaround/cludge-fix that uses a special metadata term "_" - ugly. Please help1.1KViews0likes0Comments