using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
$body = "<html><body>"
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$InputString += $Request.Query.TextString
if ($InputString -eq $null) {$InputString = "Default string"}
$body += $InputString
$body += "<br><p>Version: 11</p>"
$body += "</body></html>"
$statusCode = $Request.Query.StatusCode
if ($statusCode -eq $null) {$statusCode = "OK"}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::$statusCode
ContentType = "text/html"
Body = $body
})
Reply
New-AzSubscriptionAlias fails
When using the PowerShell command New-AzSubscriptionAlias it might fail with errors not saying what the real issue is
Errors like: “InvalidManagementGroupId” and “Subscription creation failed since provided management group id is not valid” could suggest that the ID is wrong.
But the reason can actually be that the account that PowerShell is running in context of, is missing the right: “Management Group Contributor” on the management group.

Get Azure cost for subscription including marketplace expenses with PowerShell
This will get last month consumption for a subscription including the money spend on marketplace.
$subscriptioname = "CHANGETHIS"
$roundDecimals = 2
$lastMonthBilling = (Get-Date).AddMonths(-1).ToString('yyyyMM')
# Set context to subscription
Set-azcontext -SubscriptionName $subscriptioname
# Get billing period
$BillingPeriod = Get-AzBillingPeriod -Name $lastMonthBilling
$startDate = $BillingPeriod.BillingPeriodStartDate.ToString("dd-MM-yyyy")
$endDate = $BillingPeriod.BillingPeriodEndDate.ToString("dd-MM-yyyy")
# Collect cost data
$currentCost = Get-AzConsumptionUsageDetail -StartDate $startDate -EndDate $endDate
$currentCost += Get-AzConsumptionMarketplace -StartDate $startDate -EndDate $endDate
# Write output to screen
Write-Host "Current Cost of Subscription" (Get-AzContext).Subscription.Name ":" ([math]::Round(($currentCost | Measure-Object -Property PretaxCost -Sum).sum,$roundDecimals))
Add program to start up, when you login
Great temporary email service
Get all subscriptions recursive from management groups with PowerShell
$topLvlMgmtGrp = "CHANGETHIS" # Name of the top level management group
$subscriptions = @() # Output array
# Collect data from managementgroups
$mgmtGroups = Get-AzManagementGroup -GroupId $topLvlMgmtGrp -Expand -Recurse
$children = $true
while ($children) {
$children = $false
$firstrun = $true
foreach ($entry in $mgmtGroups) {
if ($firstrun) {Clear-Variable mgmtGroups ; $firstrun = $false}
if ($entry.Children.length -gt 0) {
# Add management group to data that is being looped throught
$children = $true
$mgmtGroups += $entry.Children
}
else {
# Add subscription to output object
$subscriptions += New-Object -TypeName psobject -Property ([ordered]@{'DisplayName'=$entry.DisplayName;'SubscriptionID'=$entry.Name})
}
}
}
$subscriptions

The priority of parameters for Bicep
Enable setting for controlling power setting on lock display/screen
Powershell output to file, ensure encoding is correct
Instead of using out-file, use the method Set-Content
This give the possibility to use the parameter: “-Encoding“



