Skip to content

Commit f2a23de

Browse files
authored
Merge pull request #225338 from Blackmist/powershell
Powershell
2 parents 7c030af + 114d05c commit f2a23de

File tree

4 files changed

+180
-3
lines changed

4 files changed

+180
-3
lines changed

articles/machine-learning/how-to-manage-workspace-cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ms.custom: devx-track-azurecli, cliv2, event-tier1-build-2022
2323
2424
In this article, you learn how to create and manage Azure Machine Learning workspaces using the Azure CLI. The Azure CLI provides commands for managing Azure resources and is designed to get you working quickly with Azure, with an emphasis on automation. The machine learning extension to the CLI provides commands for working with Azure Machine Learning resources.
2525

26+
You can also manage workspaces the [Azure portal and Python SDK](how-to-manage-workspace.md), [Azure PowerShell](how-to-manage-workspace-powershell.md), or [via the VS Code extension](how-to-setup-vs-code.md).
27+
2628
## Prerequisites
2729

2830
* An **Azure subscription**. If you don't have one, try the [free or paid version of Azure Machine Learning](https://azure.microsoft.com/free/).
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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.

articles/machine-learning/how-to-manage-workspace.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ms.custom: fasttrack-edit, FY21Q4-aml-seo-hack, contperf-fy21q4, sdkv2, event-ti
2323
2424
In this article, you create, view, and delete [**Azure Machine Learning workspaces**](concept-workspace.md) for [Azure Machine Learning](overview-what-is-azure-machine-learning.md), using the [Azure portal](https://portal.azure.com) or the [SDK for Python](/python/api/overview/azure/ml/).
2525

26-
As your needs change or requirements for automation increase you can also manage workspaces [using the CLI](how-to-manage-workspace-cli.md), or [via the VS Code extension](how-to-setup-vs-code.md).
26+
As your needs change or requirements for automation increase you can also manage workspaces [using the CLI](how-to-manage-workspace-cli.md), [Azure PowerShell](how-to-manage-workspace-powershell.md), or [via the VS Code extension](how-to-setup-vs-code.md).
2727

2828
## Prerequisites
2929

@@ -79,7 +79,7 @@ You can create a workspace [directly in Azure Machine Learning studio](./quickst
7979

8080
For more information, see [Workspace SDK reference](/python/api/azure-ai-ml/azure.ai.ml.entities.workspace).
8181

82-
If you have problems in accessing your subscription, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md), as well as the [Authentication in Azure Machine Learning](https://aka.ms/aml-notebook-auth) notebook.
82+
If you have problems in accessing your subscription, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md), and the [Authentication in Azure Machine Learning](https://aka.ms/aml-notebook-auth) notebook.
8383

8484
# [Portal](#tab/azure-portal)
8585

@@ -241,7 +241,7 @@ When running machine learning tasks using the SDK, you require a MLClient object
241241

242242
[!notebook-python[](~/azureml-examples-main/sdk/python/resources/workspace/workspace.ipynb?name=ws)]
243243

244-
If you have problems in accessing your subscription, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md), as well as the [Authentication in Azure Machine Learning](https://aka.ms/aml-notebook-auth) notebook.
244+
If you have problems in accessing your subscription, see [Set up authentication for Azure Machine Learning resources and workflows](how-to-setup-authentication.md), and the [Authentication in Azure Machine Learning](https://aka.ms/aml-notebook-auth) notebook.
245245

246246
## Find a workspace
247247

articles/machine-learning/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@
314314
href: how-to-manage-workspace.md
315315
- name: Use Azure CLI
316316
href: how-to-manage-workspace-cli.md
317+
- name: Use Azure PowerShell
318+
href: how-to-manage-workspace-powershell.md
317319
- name: Use Resource Manager template
318320
displayName: arm
319321
href: how-to-create-workspace-template.md

0 commit comments

Comments
 (0)