A pulse on employees’ wellbeing, six months into the pandemic

A pulse on employees’ wellbeing, six months into the pandemic

This article is contributed. See the original author and article here.

It’s been over six months since shelter-in-place orders around the world changed work forever. At Microsoft, we’re studying this new world of work very closely,

The post A pulse on employees’ wellbeing, six months into the pandemic appeared first on Microsoft 365 Blog.

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

A pulse on employees’ wellbeing, six months into the pandemic

Making a big impact starts with making things really simple

This article is contributed. See the original author and article here.

Microsoft Endpoint Manager connects you to all the important aspects of your IT estate with native integration with Microsoft 365 and Microsoft’s advanced security, compliance, and identity solutions. Learn what’s new in Microsoft Endpoint Management and Productivity Score.

The post Making a big impact starts with making things really simple appeared first on Microsoft 365 Blog.

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

Azure Sphere + cellular connectivity: understanding security boundaries

Azure Sphere + cellular connectivity: understanding security boundaries

This article is contributed. See the original author and article here.

Azure Sphere and cellular connectivity

Cellular connectivity is one of the most common functions that customers wish to take advantage of when developing secured IoT solutions. Cellular connectivity is naturally applicable to scenarios in which Wi-Fi or Ethernet connectivity is not readily available. However, we have also seen that cellular connectivity can deliver tremendous value even in places where Ethernet or Wi-Fi are present. For instance, cellular connectivity can simplify device setup and provisioning by removing the dependency on the configuration of local network infrastructure; cellular can sidestep technical or policy obstacles and accelerate deployments.

 

Although Azure Sphere currently supports connecting through Ethernet and Wi-Fi networks only, it can be a useful building block for a cellular solution. You can introduce cellular connectivity by pairing the Azure Sphere device with a cellular-capable router device. This allows you to take advantage of Azure Sphere’s software update infrastructure, certificate-based authentication, and Azure integration while connecting over cellular.

 

When using this kind of architecture, it’s extremely important to be aware that there is a security boundary between the Azure Sphere elements and the cellular connectivity elements. Azure Sphere security does not extend beyond its own Wi-Fi or Ethernet interface. Therefore, you will want to be certain that the non-Azure Sphere parts of your solution are adequately and properly secured to ensure that the overall system (and not just the parts running on or behind Azure Sphere) is robust against security threats.

Nick Chen visual .png

Common cellular risks

Connecting a device to the internet through a cellular-enabled router introduces many similar network security risks that are present whenever you connect through other routing devices, such as the Wi-Fi access points or routers found in home and business environments. In these configurations, Azure Sphere is unable to protect the external hardware from threats like being the target of a denial-of-service attack or becoming a part of a botnet. Although the Azure Sphere parts of the system remain secured, the overall device might not be able to reach the Internet, interrupting critical functions like device telemetry and updates. This can affect your business or the customer experience you are trying to deliver.

 

To avoid any potentially disruptive surprises, it is critical that you identify the boundary between Azure Sphere and the cellular connectivity elements. On some devices this boundary may be difficult to spot, but this boundary is always present. For elements outside of the Azure Sphere security boundary, you should make sure that the manufacturer of the hardware, as well as the cellular service provider, offers the appropriate level of security, services, and support for your use case. For a deep-dive about evaluating the security boundaries and risks of the Azure Sphere cellular connectivity architecture please read our paper, “Cellular connectivity options immediately available to users of Azure Sphere.”

 

What Solutions are Available Now?

The Azure Sphere ecosystem includes a wide range of solutions representing different levels of integration between Azure Sphere and cellular connectivity. These solutions range from cellular connectivity modules suitable for additional customization to complete cellular Guardian devices ready for connection to brownfield equipment.

 

Although the options for introducing cellular connectivity to an IoT device may seem varied, fundamentally, the security boundary will be the same. Clearly understanding this boundary—where Azure Sphere security stops—and the security risks that remain to be resolved by you, your system integration partner, or your network provider will help you deliver the most secure and robust solution for your organization or for your customers.

Azure Data Explorer and Power Apps

This article is contributed. See the original author and article here.

Azure Data Explorer and Power Apps

Today’s Mission… marry the awesomeness of Azure Data Explorer and Power Apps

 

 

 

Introduction

For this exercise, imagine a customer with the following characteristics:

  • Large and growing collection of streaming data in Azure Data Explorer
  • A desire to build a low code, highly functional app to make use of this data

Objectives

The following Step-by-Step Instructions will lead to successful completion of the following objectives:

  • Instantiate Resources … prepare required Azure resources
  • Create App … demonstrate connection to Azure Data Explorer data parameterization, retrieval, and presentation

Technologies

This write-up assumes you have a Microsoft Azure subscription, Power Platform license and pre-requisite knowledge about the following technologies:

 

 

Caveats

Before we get started, some expectation setting…

  • The instructions below are not a complete path to a production solution… they were prepared with the intention of conveying basic knowledge and providing a foundation that you could tailor to fit your environment, standards, etc.
  • Keep a watchful eye on incurred costs … consider a daily assessment and use of budgets / alerts
  • Azure interface and functionality evolve rapidly; the snips below will become dated over time

Step-by-Step Instructions

Instantiate Resources

First, we will quickly run through creation of the basic resources we will need to complete this exercise. Although you can use existing Azure resources in your subscription, consider creating resources specific to this exercise to provide for future maintenance, cost analysis, reporting, etc.

Resource Group

Create this resource to group related resources, provide for simplified cost accounting and enable bulk housekeeping.

 

 

 

 

On the “Create a resource group” page, enter values for the following form items:

Subscription

Self-explanatory

Resource Group

Enter a name that is meaningful for you (and aligned with your naming standards)

Region

Select a region appropriate for your situation; take into consideration that some regions {e.g. West US and East US} see higher demand than others

 

Review settings on remaining tabs {e.g. Tags}. No additional settings are required for this exercise.

Click the “Review + create” button, validate, and then click the Create button. Allow time for processing.

 

 

Data Explorer

Use the Azure Portal to create an Azure Data Explorer Cluster.

 

 

 

 

On the “Create an Azure Data Explorer Cluster” page, enter values for the following form items:

Subscription

Self-explanatory

Resource Group

Select the resource group created in the prior step

Cluster Name

Enter a name that is meaningful for you (and aligned with your naming standards)

Region

Select the value used during Resource Group creation

Workload

Select “Compute optimized” from the dropdown

Size

Select “Extra Small (2 cores)” from the dropdown

Compute Specifications

This should be auto populated with “Standard_D11_v2” based on the Workload and Size selections

Availability Zones

Confirm default selection, “(none)”

 

Review settings on remaining tabs {e.g. Tags}. No additional settings are required for this exercise.

Click the “Review + create” button, validate, and then click the Create button. Allow time for processing.

 

 

Add Database

Use the Azure Portal to add an Azure Data Explorer Database.

 

 

 

 

In the newly created Data Explorer Cluster, click the “+ Add database” button.

 

On the “Create an Azure Data Explorer Database” popout, enter values for the following form items:

Database Name

Enter a name that is meaningful for you (and aligned with your naming standards)

Retention Period (in days)

Confirm the default value, 3650

Cache Period (in days)

Confirm the default value, 31

 

Click the Create button. Allow time for processing.

 

 

Sample Data

Follow the instructions in the “Quickstart: Ingest sample data into Azure Data Explorer” article (https://docs.microsoft.com/en-us/azure/data-explorer/ingest-sample-data) to populate sample data that we can surface in Power Apps.

 

 

 

 

Review the results so you are familiar with the data for later sections.

 

 

Power Apps

This write-up assumes that you already have a working instance of the Power Platform with necessary licensing. If not, you can get started at https://powerapps.microsoft.com/en-us/

 

 

 

 

If you are already set up, click “Sign In”.

 

 

Create Connection

Navigate to https://make.preview.powerapps.com/

 

 

 

 

Expand Data in the left-hand navigation to and click on Connections in the resulting options.

 

 

 

 

Click the “+ New connection” button.

 

 

Select “Azure Data Explorer…” in the resulting options.

 

 

 

 

Click the Create button on the “Azure Data Explorer” popup. Provide credentials as required.

 

 

 

Good Job!

 

You have successfully completed Objective #1: Instantiate Resources

 

 

Create App

Objective: Demonstrate connection to Azure Data Explorer data parameterization, retrieval, and presentation

 

Navigate to Power Apps and then Apps in the left-hand navigation.

 

 

 

 

Click the “+ New app” button in the menu bar and then Canvas from the resulting dropdown.

 

 

 

 

Click the “Tablet layout” button in the “Blank app” section.

 

 

Add Connector

Click on the Data icon on the left-hand navigation. Expand Connectors and click on “Azure Data Explorer” in the resulting options.

 

 

 

 

You should see a new area called “In your app” with “Azure Data Explorer” now included.

 

 

Advanced Settings

Click File in the menu bar. Click Save in the left-hand navigation.

 

 

 

 

Enter a meaningful name for your app. Click the Save button in the lower-right.

 

 

 

 

 

Click Settings in the resulting left-hand navigation.

 

 

 

 

Click “Advanced settings”, scroll through the resulting options and find “Dynamic schema”. Turn this feature on and restart the app as required.

 

 

Add Dropdown

Click Insert in the menu bar. Click Input in the resulting sub menu bar. Click “Drop down” in the resulting dropdown.

Click on the Advanced tab in the right-hand popout.

 

 

 

 

Populate the Items input box with: [“CALIFORNIA”,”MICHIGAN”]

 

 

With the dropdown still selected, select OnChange from the Property dropdown in the formula bar.

 

 

 

 

Enter the following formula:

ClearCollect(

    Results,

    AzureDataExplorer.listKustoResultsPost(

        “https://adxpadec.westus2.kusto.windows.net“,

        “adxpaded”,

        “StormEvents | where State == ‘” & Dropdown1.SelectedText.Value & “‘ | take 5”

    ).value

)

 

Click the “Capture schema” button. Allow time for processing.

 

 

Add Data Table

Click Insert in the menu bar. Click “Data table” in the resulting sub menu bar. Re-position the data table and consider adding a border for visibility.

 

 

 

 

Click on the Properties tab in the right-hand popout. Select Results from the “Data Source” dropdown.

Click the “Edit fields” link. Click “+ Add field” in the resulting popout. Select desired fields. Click the Add button.

 

 

Confirm Success

Click the “Preview the app” button in the upper-right of the screen.

 

 

 

 

Try the dropdown, scroll through the data table, and confirm successful data retrieval and presentation.

 

 

 

Good Job!

 

You have successfully completed Objective #2: Create App

 

 

Reference

  • Quickstart: Ingest sample data into Azure Data Explorer

https://docs.microsoft.com/en-us/azure/data-explorer/ingest-sample-data

 

  • Authoring formulas with dynamic schema in Power Apps

https://powerapps.microsoft.com/en-us/blog/authoring-formulas-with-dynamic-schema-in-power-apps/

Track progress of SQL Managed Instance create/scale request

This article is contributed. See the original author and article here.

Azure SQL Managed Instance provides management operations that you can use to automatically deploy new managed instances, update instance properties, and delete instances when no longer needed. All management operations can be categorized as follows:

  • Instance deployment (new instance creation)
  • Instance update (changing instance properties, such as vCores or reserved storage)
  • Instance deletion

As result of connectivity and deployment architecture, instance deployment and scaling are long running operations. These operation can be monitored on couple of ways, but till now neither one of them was displaying full details on operation steps and progress.

 

Managed Instance Operations API introduced

 

With instance operations API in place you can monitor progress of create and scaling requests across tools including Azure Portal, PowerShell, Azure CLI or using REST API itself. API and tools have in place commands for retrieving operation details and canceling ongoing operations.

 

Get operation details

 

Command for retrieving operation details gives insight into:

  • Operation start time
  • Operation parameters – set of properties that retrieves a list of current and requested parameters for scaling operation. In case of create operation only requested parameters are returned
  • Operation status – parameter that shows if operation is in progress, completed or has failed
  • Is operation cancelable – deployment steps in operations API are high level logical steps. Some of the micro steps beneath cannot be abandoned. This parameter represents if operation can be canceled or not in current point of time
  • Operation steps – set of properties that retrieves information on current step, total number of steps and each individual step details

Example of the API call for getting list of operations for the specific managed instance:

 

GET https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/my-rg/providers/Microsoft.Sql/managedInstances/my-managed-instance/operations?api-version=2019-06-01-preview

 

Example of the API response with list of operations:

 

[
   {
      "properties":{
         "managedInstanceName":"my-managed-instance",
         "operation":"UpsertManagedServer",
         "operationFriendlyName":"UPDATE MANAGED SERVER",
         "percentComplete":100,
         "startTime":"2019-12-06T11:08:44.49Z",
         "state":"Cancelled",
         "isCancellable":false
      },
      "id":"/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/my-rg/providers/Microsoft.Sql/managedInstances/my-managed-instance/operations/11111111-2222-2222-2222-111111111111",
      "name":"11111111-2222-2222-2222-111111111111",
      "type":"Microsoft.Sql/managedInstances/operations"
   },
   {
      "properties":{
         "managedInstanceName":"my-managed-instance",
         "operation":"UpsertManagedServer",
         "operationFriendlyName":"UPDATE MANAGED SERVER",
         "percentComplete":0,
         "startTime":"2019-12-06T11:08:44.49Z",
         "state":"InProgress",
         "isCancellable":true,
         "operationSteps":{
            "totalSteps":"6",
            "currentStep":2,
            "stepsList":[
               {
                  "order":1,
                  "name":"Request validation",
                  "status":"Completed"
               },
               {
                  "order":2,
                  "name":"Virtual Cluster resize/creation",
                  "status":"InProgress"
               },
               {
                  "order":3,
                  "name":"New SQL Instance Startup",
                  "status":"NotStarted"
               },
               {
                  "order":4,
                  "name":"Seeding database files",
                  "status":"NotStarted"
               },
               {
                  "order":5,
                  "name":"Preparing Failover and Failover",
                  "status":"NotStarted"
               },
               {
                  "order":6,
                  "name":"Old SQL Instance cleanup",
                  "status":"NotStarted"
               }
            ]
         }
      },
      "id":"/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/my-rg/providers/Microsoft.Sql/managedInstances/my-managed-instance/operations/11111111-1111-1111-1111-111111111111",
      "name":"11111111-1111-1111-1111-111111111111",
      "type":"Microsoft.Sql/managedInstances/operations"
   }
]

 

 

Operation is visible only 24 hours in API response. For full explanation of the API visit Monitoring Azure SQL Managed Instance management operations.

 

Cancel operation

 

Cancel operation is executed for specific operation performed on the managed instance. Operation names that are unique and that can be found as part of the GET operation details response, are used for this purpose.

 

Example of the API call for canceling operation:

 

POST https://management.azure.com/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/my-rg/providers/Microsoft.Sql/managedInstances/my-managed-instance/operations/11111111-1111-1111-1111-111111111111/cancel?api-version=2019-06-01-preview

 

 

Managed Instance Operations API use cases and examples

 

Get Operation

 

Command for returning operation with operation steps enables you to take dependent actions based on operation progress or simply track progress of the submitted operation.

 

Note: Examples displayed in this article are just the basics and there is a space for improvement in terms of additional validations or parametrization. Main goal of these examples is to bring closer  benefits of management operations API.

 

Example 1: deploy resources dependent on managed instance deployment

In create operation or general purpose vCores scaling, step with virtual cluster resize/creation is the longest one. After it is completed you could start spinning up some other environment or app that will be connected to the managed instance as remaining steps are the shorter one and create/update operation is close to finish. In both scenarios (create or GP vCores update) virtual cluster resize/creation step is second one. For full list of steps and their order of execution visit Management Operations overview documentation article. PowerShell example for the scenario could look like the following:

 

#Define parameters
$managedInstance = "managed-instance-name"
$resourceGroup = "resource-group-name"
$location = "westcentralus"
$subnetId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name/providers/Microsoft.Network/virtualNetworks/vnet-name/subnets/subnet-name"
$licenseType = "LicenseIncluded"
$vCores = 8
$storageSizeInGB = 256
$edition = "GeneralPurpose"
$hardwareGen = "Gen5"

#New SQL Managed Instance. Perform it As Job so script could proceed further.
$myNewMI = New-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup -Location $location -AdministratorCredential (Get-Credential) -SubnetId $subnetId -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -VCore $vCores -Edition $edition -ComputeGeneration $hardwareGen -AsJob

#Wait for 5 minutes for validation to complete
Start-Sleep -s 300

#Get list of ongoing management operations for the instance
$managementOperations = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup

#Iterate over management operations to find ongoing one
foreach ($mo in $managementOperations ) {
	if($mo.State -eq "InProgress"){
		#Create ongoing operation object
        $ongoingOperation = $mo
		break
	}
}

#If there is ongoing operation
if ($ongoingOperation) {
    $operationName = $ongoingOperation.Name
    $operationSteps = $ongoingOperation.operationSteps
    $operationStep = $operationSteps.currentStep

    #While operation is in progress and operation step is less than 3 (as step 2 is virtual cluster resize/creation) do not proceed further.
    #Check state each 10 minutes (600 seconds)
    
    Write-Host "Operation status is: " $ongoingOperation.State
    Write-Host "Operation step is: " $operationStep
    
    while($ongoingOperation.State -eq "InProgress" -and $operationStep -lt 3) {
        Write-Host "Operation status is: " $ongoingOperation.State
        Start-Sleep -s 600
        $ongoingOperation = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $operationName
        $operationSteps = $ongoingOperation.operationSteps
        $operationStep = $operationSteps.currentStep
    }
    
    Write-Host "Operation result is: " $ongoingOperation.State
    Write-Host "Operation step is: " $operationStep

    #Here goes the code for starting dependent deployment
}

 

 

Example 2: deploy managed instances as part of the same DNS zone

Another scenario could be deploying two managed instances that should be part of the failover group. First instance deployment is started and operation status is checked. In addition to operation status, we can check if DNS zone field is defined for the managed instance. As soon as it is defined, we could start another instance deployment as part of the same DNS zone. Example:

 

#Define parameters
$managedInstance = "managed-instance-name"
$resourceGroup = "resource-group-name"
$location = "westcentralus"
$subnetId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name/providers/Microsoft.Network/virtualNetworks/vnet-name/subnets/subnet-name"
$licenseType = "LicenseIncluded"
$vCores = 8
$storageSizeInGB = 256
$edition = "GeneralPurpose"
$hardwareGen = "Gen5"

#New SQL Managed Instance. Perform it As Job so script could proceed further.
$myNewMI = New-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup -Location $location -AdministratorCredential (Get-Credential) -SubnetId $subnetId -LicenseType $licenseType -StorageSizeInGB $storageSizeInGB -VCore $vCores -Edition $edition -ComputeGeneration $hardwareGen -Force -AsJob

#Wait for 5 minutes for validation to complete
Start-Sleep -s 300

#Get list of ongoing management operations for the instance
$managementOperations = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup

#Get SQL Managed Instance object and DNS zone property
$newInstance = Get-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup

#Iterate over management operations to find ongoing one
foreach ($mo in $managementOperations ) {
	if($mo.State -eq "InProgress"){
		#Create ongoing operation object
		$ongoingOperation = $mo
		break
	}
}

#If there is ongoing operation
if ($ongoingOperation) {
    $operationName = $ongoingOperation.Name
    #While operation is in progress and DNS zone is not configured do not proceed further.
    #Check state each 10 minutes (600 seconds)
    
    Write-Host "Operation status is: " $ongoingOperation.State
    
    while($ongoingOperation.State -eq "InProgress" -and $null -eq $newInstance.DnsZone) {
        Write-Host "Operation status is: " $ongoingOperation.State
        Start-Sleep -s 600
        $ongoingOperation = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $operationName
        $newInstance = Get-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup
    }
    
    Write-Host "Operation result is: " $ongoingOperation.State
    Write-Host "DNS Zone is: " $newInstance.DnsZone

    #Here goes the code for starting second instance deployment

    #Define parameters
    $managedInstanceFOG = "managed-instance-name-fog"
    $resourceGroupFOG = "resource-group-name-fog"
    $locationFOG = "westcentralus-fog"
    $subnetIdFOG = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resource-group-name-fog/providers/Microsoft.Network/virtualNetworks/vnet-name-fog/subnets/subnet-name-fog"
    $licenseTypeFOG = "LicenseIncluded"

    $myNewMIForFOG = New-AzSqlInstance -Name $managedInstanceFOG -ResourceGroupName $resourceGroupFOG -Location $locationFOG -AdministratorCredential (Get-Credential) -SubnetId $subnetIdFOG -LicenseType $licenseTypeFOG -StorageSizeInGB $storageSizeInGB -VCore $vCores -Edition $edition -ComputeGeneration $hardwareGen -Force -AsJob
}

 

 

Example 3: Scale up managed instance and kick off any data processing job that requires more compute

Customers are often facing with a situation where there are periodic jobs or tasks that require higher compute power which requires managed instance vCores scaling. Flow starts with instance scale up, then performing ETL or ML job (or any other) and then doing the instance scale down. Example script for this scenario:

 

#Define parameters
$managedInstance = "managed-instance-name"
$resourceGroup = "resource-group-name"
$sourceVcores = 8
$destVcores = 16

#Get SQL Managed Instance
$initialInstance = Get-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup
Write-Host "Instance vCores value is: " $initialInstance.VCores

#Update SQL Managed Instance to 16 vCores. Force to skip verification. Perform it As Job so script could proceed further.
Set-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup -VCore $destVcores -Force -AsJob

#Get list of ongoing management operations for the instance
$managementOperations = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup

#Iterate over management operations to find ongoing one
foreach ($mo in $managementOperations ) {
	if($mo.State -eq "InProgress"){
		#Create ongoing operation object
		$ongoingOperation = $mo
		break
	}
}

#If there is ongoing operation
if ($ongoingOperation) {
    $operationName = $ongoingOperation.Name
    
    #While operation is in progress do not proceed further. Check state each 10 minutes (600 seconds)
    Write-Host "Operation status is: " $ongoingOperation.State
    while($ongoingOperation.State -eq "InProgress") {
        Write-Host "Operation status is: " $ongoingOperation.State
        Start-Sleep -s 600
        $ongoingOperation = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $operationName
    }
    Write-Host "Operation result is: " $ongoingOperation.State

    #Get SQL Managed Instance and check if vCores are increased. If vCores are increased, start ML Process
    $scaledInstance = Get-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup
    Write-Host "Instance vCores value is: " $scaledInstance.VCores
    if($scaledInstance.VCores -eq $destVcores ) {
        #Here goes the code for starting ML process which will be triggered after scaling operation is completed
        
        #Add code

        #After ML process is completed, scale down MI to 8 vCores. If there is need, adjust this part so it depends on ML result
        $restoredInstance = Set-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup -VCore $sourceVcores
    }
}

 

 

Cancel operation

 

Cancellation of ongoing operation can be a handful when create or update request is submitted with wrong parameters or when create/update operation is running for longer than expected.

 

Example 1: Cancel create/update request without any condition

 

$managedInstance = "yourInstanceName"
$resourceGroup = "yourResourceGroupName"

$managementOperations = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup

foreach ($mo in $managementOperations ) {
	if($mo.State -eq "InProgress" -and $mo.IsCancellable){
		$cancelRequest = Stop-AzSqlInstanceOperation -ResourceGroupName $resourceGroup -ManagedInstanceName $managedInstance -Name $mo.Name
		Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $mo.Name
	}
}

 

 

Example 2: Cancel operation that is running for more than 10 hours and create a support ticket

 

$managedInstance = "yourInstanceName"
$resourceGroup = "yourResourceGroupName"

$managementOperations = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup

#Iterate over management operations to find ongoing one
foreach ($mo in $managementOperations ) {
	if($mo.State -eq "InProgress"){
		#Create ongoing operation object		
		$ongoingOperation = $mo
		break
	}
}

#If there is ongoing operation
if ($ongoingOperation) {
	$operationName = $ongoingOperation.Name
	$currentDateTime = Get-Date
	$startDateTime = $ongoingOperation.StartTime
	$timeDiff = New-TimeSpan –Start $startDateTime –End $currentDateTime

	#While operation is in progress and lasts less then 10 hours do not proceed further. Check state each 10 minutes (600 seconds)
	Write-Host "Operation status is: " $ongoingOperation.State
	
	while($ongoingOperation.State -eq "InProgress" -and $timeDiff.Hours -le 10) {
		Write-Host "Operation status is: " $ongoingOperation.State

		Start-Sleep -s 600
		$ongoingOperation = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $operationName
		$currentDateTime = Get-Date
		$timeDiff = New-TimeSpan –Start $startDateTime –End $currentDateTime
	}
	Write-Host "Operation result is: " $ongoingOperation.State
	$ongoingOperation = Get-AzSqlInstanceOperation -ManagedInstanceName $managedInstance  -ResourceGroupName $resourceGroup -Name $operationName

	#If operation is still in progress, and we are out of the loop (which means operation is running for more then 10 hours) create a support ticket
	if($ongoingOperation.State -eq "InProgress"){
		$managedInstance = Get-AzSqlInstance -Name $managedInstance -ResourceGroupName $resourceGroup		
		
		# Service GUID 9b629e89-4ea0-53ec-9409-1579b8c41453 = SQL Database Managed Instance - For list of GUIDs check Get-AzSupportService
		# Problem Classification GUID ac342689-043e-d79b-6665-7edda4ecc61c = Service Tiers or Scaling Resources / Scaling an instance (compute, storage, and service tier changes) - For list of GUIDs check Get-AzSupportProblemClassification
		$problemClassificationId = "/providers/Microsoft.Support/services/9b629e89-4ea0-53ec-9409-1579b8c41453/problemClassifications/ac342689-043e-d79b-6665-7edda4ecc61c"
		$supportTicket = New-AzSupportTicket -Name "test1" -Title "Test" -Description "Test" -Severity "minimal" -ProblemClassificationId $problemClassificationId -TechnicalTicketResourceId $managedInstance.Id -CustomerContactDetail @{FirstName = "first" ; LastName = "last" ; PreferredTimeZone = "pacific standard time" ; PreferredSupportLanguage = "en-us" ; Country = "USA" ; PreferredContactMethod = "Email" ; PrimaryEmailAddress = "user@contoso.com"}
	}
}