Skip to content

Files

Latest commit

93f0cdd · Mar 18, 2022

History

History
103 lines (68 loc) · 4.89 KB

samples-powershell.md

File metadata and controls

103 lines (68 loc) · 4.89 KB
title description ms.topic ms.author author ms.date
Azure PowerShell Samples
Learn about Azure PowerShell scripts. These samples help you manage labs in Azure Lab Services.
sample
rosemalcolm
RoseHJM
02/02/2022

Azure PowerShell samples for Azure Lab Services

This article includes the sample Azure PowerShell scripts for Azure Lab Services.

[!INCLUDE updated-for-az]

[!INCLUDE sample-powershell-install]

This article includes the following samples:

Script Description
Add an external user to a lab This PowerShell script adds an external user to a lab in Azure DevTest Labs.
Add marketplace images to a lab This PowerShell script adds marketplace images to a lab in Azure DevTest Labs.
Create a custom image from a virtual hard drive (VHD) This PowerShell script creates a custom image in a lab in Azure DevTest Labs.
Create a custom role in a lab This PowerShell script creates a custom role in a lab in Azure Lab Services.
Set allowed virtual machine sizes in a lab This PowerShell script sets allowed virtual machine sizes in a lab.

Prerequisites

All of these scripts have the following prerequisite:

Add an external user to a lab

This sample PowerShell script adds an external user to a lab in Azure DevTest Labs.

:::code language="powershell" source="../../powershell_scripts/devtest-lab/add-external-user-to-lab/add-external-user-to-custom-lab.ps1":::

This script uses the following commands:

Command Notes
Get-AzADUser Retries the user object from Azure active directory.
New-AzRoleAssignment Assigns the specified role to the specified principal, at the specified scope.

Add a marketplace image to a lab

This sample PowerShell script adds a marketplace image to a lab in Azure DevTest Labs.

:::code language="powershell" source="../../powershell_scripts/devtest-lab/add-marketplace-images-to-lab/add-marketplace-images-to-lab.ps1":::

This script uses the following commands:

Command Notes
Get-AzResource Gets resources.
Set-AzResource Modifies a resource.
New-AzResource Create a resource.

Create a custom image from a VHD file

This sample PowerShell script creates a custom image from a VHD file in Azure Lab Services.

:::code language="powershell" source="../../powershell_scripts/devtest-lab/create-custom-image-from-vhd/create-custom-image-from-vhd.ps1":::

This script uses the following commands:

Command Notes
Get-AzResource Gets resources.
Get-AzStorageAccountKey Gets the access keys for an Azure Storage account.
New-AzResourceGroupDeployment Adds an Azure deployment to a resource group.

Create a custom role in a lab

This sample PowerShell script creates a custom role to use in a lab in Azure DevTest Labs.

:::code language="powershell" source="../../powershell_scripts/devtest-lab/create-custom-role-in-lab/create-custom-role-in-lab.ps1":::

This script uses the following commands:

Command Notes
Get-AzProviderOperation Gets the operations for an Azure resource provider that are securable using Azure role-based access control.
Get-AzRoleDefinition Lists all Azure roles that are available for assignment.
New-AzRoleDefinition Creates a custom role.

Set allowed virtual machine sizes

This sample PowerShell script sets allowed virtual machine sizes in Azure Lab Services.

:::code language="powershell" source="../../powershell_scripts/devtest-lab/set-allowed-vm-sizes-in-lab/set-allowed-vm-sizes-in-lab.ps1":::

Command Notes
Get-AzResource Gets resources.
Set-AzResource Modifies a resource.
New-AzResource Create a resource.

Next steps

For more information on Azure PowerShell, see Azure PowerShell documentation.