|
| 1 | +--- |
| 2 | +title: Create workspaces with Azure PowerShell |
| 3 | +titleSuffix: Azure Machine Learning |
| 4 | +description: Learn how to use the Azure PowerShell module to create and manage a new Azure Machine Learning workspace. |
| 5 | +services: machine-learning |
| 6 | +ms.service: machine-learning |
| 7 | +ms.subservice: core |
| 8 | +ms.author: deeikele |
| 9 | +author: deeikele |
| 10 | +ms.reviewer: larryfr |
| 11 | +ms.date: 01/26/2023 |
| 12 | +ms.topic: how-to |
| 13 | +ms.custom: devx-track-azurepowershell |
| 14 | +--- |
| 15 | + |
| 16 | +# Manage Azure Machine Learning workspaces using Azure PowerShell |
| 17 | + |
| 18 | +Use the Azure PowerShell module for Azure Machine Learning to create and manage your Azure Machine Learning workspaces. For a full list of the Azure PowerShell cmdlets for Azure Machine Learning, see the [Az.MachineLearningServices](/powershell/module/az.machinelearningservices) reference documentation. |
| 19 | + |
| 20 | +You can also manage workspaces [using the Azure CLI](how-to-manage-workspace-cli.md), [Azure portal and Python SDK](how-to-manage-workspace.md), or [via the VS Code extension](how-to-setup-vs-code.md). |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +- An **Azure subscription**. If you don't have one, try the [free or paid version of Azure Machine Learning](https://azure.microsoft.com/free/). |
| 25 | +- The [Azure PowerShell module](https://www.powershellgallery.com/packages/Az). To make sure you have the latest version, see [Install the Azure PowerShell module](/powershell/azure/install-az-ps). |
| 26 | + |
| 27 | + > [!IMPORTANT] |
| 28 | + > While the **Az.MachineLearningServices** PowerShell module is in preview, you must install it |
| 29 | + > separately using the `Install-Module` cmdlet. |
| 30 | +
|
| 31 | + ```azurepowershell-interactive |
| 32 | + Install-Module -Name Az.MachineLearningServices -Scope CurrentUser -Repository PSGallery -Force |
| 33 | +## Sign in to Azure |
| 34 | +
|
| 35 | +Sign in to your Azure subscription with the `Connect-AzAccount` command and follow the on-screen directions. |
| 36 | +
|
| 37 | +```azurepowershell |
| 38 | +Connect-AzAccount |
| 39 | +``` |
| 40 | + |
| 41 | +If you don't know which location you want to use, you can list the available locations. Display the list of locations by using the following code example and find the one you want to use. This example uses **eastus**. Store the location in a variable and use the variable so you can change it in one place. |
| 42 | + |
| 43 | +```azurepowershell-interactive |
| 44 | +Get-AzLocation | Select-Object -Property Location |
| 45 | +$Location = 'eastus' |
| 46 | +``` |
| 47 | + |
| 48 | +## Create a resource group |
| 49 | + |
| 50 | +Create an Azure resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup). A resource group is a logical container into which Azure resources are deployed and managed. |
| 51 | + |
| 52 | +```azurepowershell-interactive |
| 53 | +$ResourceGroup = 'MyResourceGroup' |
| 54 | +New-AzResourceGroup -Name $ResourceGroup -Location $Location |
| 55 | +``` |
| 56 | + |
| 57 | +## Create dependency resources |
| 58 | + |
| 59 | +An Azure Machine Learning workspace depends on the following Azure resources: |
| 60 | + |
| 61 | +* Application Insights |
| 62 | +* Azure Key Vault |
| 63 | +* Azure Storage Account |
| 64 | + |
| 65 | +Use the following commands to create these resources and retrieve the Azure Resource Manager ID for each of them: |
| 66 | + |
| 67 | +> [!NOTE] |
| 68 | +> The Microsoft.Insights resource provider must be registered for your subscription prior to running |
| 69 | +> the following commands. This is a one time registration. Use |
| 70 | +> `Register-AzResourceProvider -ProviderNamespace Microsoft.Insights` to perform the registration. |
| 71 | +
|
| 72 | +1. Create the Application Insights instance: |
| 73 | + |
| 74 | + ```azurepowershell-interactive |
| 75 | + $AppInsights = 'MyAppInsights' |
| 76 | + New-AzApplicationInsights -Name $AppInsights -ResourceGroupName $ResourceGroup -Location $Location |
| 77 | + $appid = (Get-AzResource -Name $AppInsights -ResourceGroupName $ResourceGroup).ResourceId |
| 78 | +
|
| 79 | +1. Create the Azure Key Vault: |
| 80 | +
|
| 81 | + > [!IMPORTANT] |
| 82 | + > Each key vault must have a unique name. Replace `MyKeyVault` with the name of your key vault in the following example. |
| 83 | +
|
| 84 | + ```azurepowershell-interactive |
| 85 | + $KeyVault = 'MyKeyVault' |
| 86 | + New-AzKeyVault -Name $KeyVault -ResourceGroupName $ResourceGroup -Location $Location |
| 87 | + $kvid = (Get-AzResource -Name $KeyVault -ResourceGroupName $ResourceGroup).ResourceId |
| 88 | +
|
| 89 | +1. Create the Azure Storage Account: |
| 90 | +
|
| 91 | + > [!IMPORTANT] |
| 92 | + > Each storage account must have a unique name. Replace `MyStorage` with the name of your storage account in the following example. You can use `Get-AzStorageAccountNameAvailability -Name 'YourUniqueName'` to verify the name before running the following example. |
| 93 | +
|
| 94 | + ```azurepowershell-interactive |
| 95 | + $Storage = 'MyStorage' |
| 96 | +
|
| 97 | + $storageParams = @{ |
| 98 | + Name = $Storage |
| 99 | + ResourceGroupName = $ResourceGroup |
| 100 | + Location = $Location |
| 101 | + SkuName = 'Standard_LRS' |
| 102 | + Kind = 'StorageV2' |
| 103 | + } |
| 104 | + New-AzStorageAccount @storageParams |
| 105 | +
|
| 106 | + $storeid = (Get-AzResource -Name $Storage -ResourceGroupName $ResourceGroup).ResourceId |
| 107 | +
|
| 108 | +## Create a workspace |
| 109 | +
|
| 110 | +> [!NOTE] |
| 111 | +> The Microsoft.MachineLearningServices resource provider must be registered for your subscription |
| 112 | +> prior to running the following commands. This is a one time registration. Use |
| 113 | +> `Register-AzResourceProvider -ProviderNamespace Microsoft.MachineLearningServices` to perform the |
| 114 | +> registration. |
| 115 | +
|
| 116 | +The following command creates the workspace and configures it to use the services created previously. It also configures the workspace to use a system-assigned managed identity, which is used to access these services. For more information on using managed identities with Azure Machine Learning, see the [Set up authentication to other services](how-to-identity-based-service-authentication.md) article. |
| 117 | +
|
| 118 | +```azurepowershell-interactive |
| 119 | +$Workspace = 'MyWorkspace' |
| 120 | +$mlWorkspaceParams = @{ |
| 121 | + Name = $Workspace |
| 122 | + ResourceGroupName = $ResourceGroup |
| 123 | + Location = $Location |
| 124 | + ApplicationInsightID = $appid |
| 125 | + KeyVaultId = $kvid |
| 126 | + StorageAccountId = $storeid |
| 127 | + IdentityType = 'SystemAssigned' |
| 128 | +} |
| 129 | +New-AzMLWorkspace @mlWorkspaceParams |
| 130 | +``` |
| 131 | + |
| 132 | +## Get workspace information |
| 133 | + |
| 134 | +To retrieve a list of workspaces, use the following command: |
| 135 | + |
| 136 | +```azurepowershell-interactive |
| 137 | +Get-AzMLWorkspace |
| 138 | +``` |
| 139 | + |
| 140 | +To retrieve information on a specific workspace, provide the name and resource group information: |
| 141 | + |
| 142 | +```azurepowershell-interactive |
| 143 | +Get-AzMLWorkspace -Name $Workspace -ResourceGroupName $ResourceGroup |
| 144 | +``` |
| 145 | + |
| 146 | +## Delete a workspace |
| 147 | + |
| 148 | +[!INCLUDE [machine-learning-delete-workspace](../../includes/machine-learning-delete-workspace.md)] |
| 149 | + |
| 150 | +To delete a workspace after it's no longer needed, use the following command: |
| 151 | + |
| 152 | +```azurepowershell-interactive |
| 153 | +Remove-AzMLWorkspace -Name $Workspace -ResourceGroupName $ResourceGroup |
| 154 | +``` |
| 155 | + |
| 156 | +> [!IMPORTANT] |
| 157 | +> Deleting a workspace does not delete the application insight, storage account, key vault, or container registry used by the workspace. |
| 158 | +
|
| 159 | +You can also delete the resource group, which deletes the workspace and all other Azure resources in the resource group. To delete the resource group, use the following command: |
| 160 | + |
| 161 | +```azurepowershell-interactive |
| 162 | +Remove-AzResourceGroup -Name $ResourceGroup |
| 163 | +``` |
| 164 | + |
| 165 | +## Next steps |
| 166 | + |
| 167 | +To check for problems with your workspace, see [How to use workspace diagnostics](how-to-workspace-diagnostic-api.md). |
| 168 | + |
| 169 | +To learn how to move a workspace to a new Azure subscription, see [How to move a workspace](how-to-move-workspace.md). |
| 170 | + |
| 171 | +For information on how to keep your Azure ML up to date with the latest security updates, see [Vulnerability management](concept-vulnerability-management.md). |
| 172 | + |
| 173 | +To learn how to train an ML model with your workspace, see the [Azure Machine Learning in a day](tutorial-azure-ml-in-a-day.md) tutorial. |
0 commit comments