What is windows azure powershell

Install Azure PowerShell

This article explains how to install the Azure PowerShell modules using PowerShellGet. These instructions work on Windows, macOS, and Linux platforms.

Azure PowerShell is also available in Azure Cloud Shell and is now preinstalled in Docker images.

Requirements

PowerShell 7.x and later is the recommended version of PowerShell for use with Azure PowerShell on all platforms.

Azure PowerShell works with PowerShell 6.2.4 and later on all platforms. It is also supported with PowerShell 5.1 on Windows. Install the latest version of PowerShell available for your operating system. Azure PowerShell has no additional requirements when run on PowerShell 6.2.4 and later.

To check your PowerShell version, run the command:

To use Azure PowerShell in PowerShell 5.1 on Windows:

  1. Update to Windows PowerShell 5.1. If you’re on Windows 10 version 1607 or higher, you already have PowerShell 5.1 installed.
  2. Install .NET Framework 4.7.2 or later.
  3. Make sure you have the latest version of PowerShellGet. Run Install-Module -Name PowerShellGet -Force .

Install the Azure PowerShell module

We do not support having both the AzureRM and Az modules installed for PowerShell 5.1 on Windows at the same time. If you need to keep AzureRM available on your system, install the Az module for PowerShell 6.2.4 or later.

Using the PowerShellGet cmdlets is the preferred installation method. Install the Az module for the current user only. This is the recommended installation scope. This method works the same on Windows, macOS, and Linux platforms. Run the following command from a PowerShell session:

By default, the PowerShell gallery isn’t configured as a trusted repository for PowerShellGet. The first time you use the PSGallery you see the following prompt:

Answer Yes or Yes to All to continue with the installation.

Installing the module for all users on a system requires elevated privileges. Start the PowerShell session using Run as administrator in Windows or use the sudo command on macOS or Linux:

The Az module is a rollup module for the Azure PowerShell cmdlets. Installing it downloads all of the generally available Az PowerShell modules, and makes their cmdlets available for use.

Install offline

In some environments, it’s not possible to connect to the PowerShell Gallery. In those situations, you can still install offline using one of these methods:

Download the modules to another location in your network and use that as an installation source. This method allows you to cache PowerShell modules on a single server or file share to be deployed with PowerShellGet to any disconnected systems. Learn how to set up a local repository and install on disconnected systems with Working with local PowerShellGet repositories.

Download the Azure PowerShell MSI to a machine connected to the network, and then copy the installer to systems without access to PowerShell Gallery. Keep in mind that the MSI installer only works for PowerShell 5.1 on Windows.

Save the module with Save-Module to a file share, or save it to another source and manually copy it to other machines:

Troubleshooting

Here are some common problems seen when installing the Azure PowerShell module. If you experience a problem not listed here, file an issue on GitHub.

Proxy blocks connection

If you get errors from Install-Module that indicate the PowerShell Gallery is unreachable, you may be behind a proxy. Different operating systems and network environment have different requirements for configuring a system-wide proxy. Contact your system administrator for your proxy settings and how to configure them for your environment.

PowerShell itself may not be configured to use this proxy automatically. With PowerShell 5.1 and later, configure the PowerShell session to use a proxy using the following commands:

If your operating system credentials are configured correctly, this configuration routes PowerShell requests through the proxy. To have this setting persist between sessions, add the commands to your PowerShell profile.

To install the package, your proxy needs to allow HTTPS connections to the following address:

Sign in

To start working with Azure PowerShell, sign in with your Azure credentials.

If you’ve disabled module autoloading, manually import the module with Import-Module -Name Az . Because of the way the module is structured, this can take a few seconds.

Читайте также:  Как посмотреть файловые дескрипторы linux

You’ll need to repeat these steps for every new PowerShell session you start. To learn how to persist your Azure sign in across PowerShell sessions, see Persist user credentials across PowerShell sessions.

Update the Azure PowerShell module

To update any PowerShell module, you should use the same method used to install the module. For example, if you originally used Install-Module , then you should use Update-Module to get the latest version. If you originally used the MSI package then you should download and install the new MSI package.

The PowerShellGet cmdlets cannot update modules that were installed from an MSI package. MSI packages do not update modules that were installed using PowerShellGet. If you have any issues updating using PowershellGet, then you should reinstall, rather than update. Reinstalling is done the same way as installing, but you need to add the -Force parameter:

Unlike MSI-based installations, installing or updating using PowerShellGet does not remove older versions that may exist on your system. To remove old versions of Azure PowerShell from your system, see Uninstall the Azure PowerShell module. For more information about MSI-based installations, see Install Azure PowerShell with an MSI.

Use multiple versions of Azure PowerShell

It’s possible to install more than one version of Azure PowerShell. To check if you have multiple versions of Azure PowerShell installed, use the following command:

To remove a version of Azure PowerShell, see Uninstall the Azure PowerShell module.

If you have more than one version of the module installed, module autoload and Import-Module load the latest version by default.

You can install or load a specific version of the Az module using the -RequiredVersion parameter:

Use multiple repositories with PowerShellGet

The Repository parameter is required if you have added additional repositories to PowerShellGet on your system and the Az module can be found in more than one of them.

Provide feedback

If you find a bug in Azure PowerShell, file an issue on GitHub. To provide feedback from the command line, use the Send-Feedback cmdlet.

Next Steps

To learn more about the Azure PowerShell modules and their features, see Get Started with Azure PowerShell. If you’re familiar with Azure PowerShell and need to migrate from AzureRM, see Migrate from AzureRM to Az.

Install Azure PowerShell on Windows with PowerShellGet

Because Az PowerShell modules now have all the capabilities of AzureRM PowerShell modules and more, we’ll retire AzureRM PowerShell modules on 29 February 2024.

To avoid service interruptions, update your scripts that use AzureRM PowerShell modules to use Az PowerShell modules by 29 February 2024. To automatically update your scripts, follow the quickstart guide.

This article explains the steps to install the Azure PowerShell modules for PowerShell 5.x for Windows using PowerShellGet. PowerShellGet and module management is the preferred way to install Azure PowerShell but if you would rather install with the Web Platform Installer or MSI package, see Other installation methods.

The Azure classic deployment model is not supported by this version of Azure PowerShell. For support for classic deployments, follow the instructions in Install the Azure PowerShell Service Management module.

The AzureRM module is not supported for macOS or Linux. To use Azure PowerShell cmdlets on these platforms, Install the Az module.

Requirements

Starting with Azure PowerShell version 6.0, Azure PowerShell requires PowerShell version 5.0. To check the version of PowerShell running on your machine, run the following command:

The module described in this document, AzureRM, uses .NET Framework. This makes it incompatible with PowerShell 6.0, which uses .NET Core. If you are using PowerShell 6.0, follow the installation instructions for macOS and Linux.

Install the Azure PowerShell module

You need elevated privileges to install modules from the PowerShell Gallery. To install Azure PowerShell, run the following command in an elevated session:

If you have a version older than 2.8.5.201 of NuGet, you are prompted to download and install the latest version of NuGet.

By default, the PowerShell gallery isn’t configured as a trusted repository for PowerShellGet. The first time you use the PSGallery you see the following prompt:

Answer Yes or Yes to All to continue with the installation.

The AzureRM module is a rollup module for the Azure PowerShell cmdlets. Installing it downloads all of the available Azure Resource Manager modules, and makes their cmdlets available for use.

Sign in

To start working with Azure PowerShell, sign in with your Azure credentials.

If you’ve disabled module autoloading, you need to manually import the module with Import-Module AzureRM . Because of the way the module is structured, this can take a few seconds.

You’ll need to repeat these steps for every new PowerShell session you start. To learn how to persist your Azure sign-in across PowerShell sessions, see Persist user credentials across PowerShell sessions.

Update the Azure PowerShell module

You can update your Azure PowerShell installation by running Update-Module. This command does not uninstall earlier versions.

If you want to remove older versions of Azure PowerShell from your system, see Uninstall the Azure PowerShell module.

Читайте также:  Как работает терминал windows

Use multiple versions of Azure PowerShell

It’s possible to install more than one version of Azure PowerShell. To check if you have multiple versions of Azure PowerShell installed, use the following command:

To remove a version of Azure PowerShell, see Uninstall the Azure PowerShell module.

You might need more than one version if you work with on-premises Azure Stack resources, run an older version of Windows, or use the Azure classic deployment model. To install an older version, provide the -RequiredVersion argument when installing.

When loading the Azure PowerShell module the latest version is loaded by default. To load a different version, provide the -RequiredVersion argument.

Provide feedback

If you find a bug when using Azure Powershell, file an issue on GitHub. To provide feedback from the command line, use the Send-Feedback cmdlet.

Next Steps

To get started using Azure PowerShell, see Get Started with Azure PowerShell to learn more about the module and its features.

Quickstart: Create and manage an Azure file share with Azure PowerShell

This guide walks you through the basics of working with Azure file shares with PowerShell. Azure file shares are just like other file shares, but stored in the cloud and backed by the Azure platform. Azure File shares support the industry standard Server Message Block (SMB) protocol, the Network File System (NFS) protocol (preview), and enables file sharing across multiple machines, applications, and instances.

If you don’t have an Azure subscription, create a free account before you begin.

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article without having to install anything on your local environment.

To start Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn’t automatically copy the code to Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal.

To run the code in this article in Azure Cloud Shell:

Start Cloud Shell.

Select the Copy button on a code block to copy the code.

Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

Select Enter to run the code.

If you would like to install and use the PowerShell locally, this guide requires the Azure PowerShell module Az version 0.7 or later. To find out which version of the Azure PowerShell module you are running, execute Get-Module -ListAvailable Az . If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Login-AzAccount to login to your Azure account.

Create a resource group

A resource group is a logical container into which Azure resources are deployed and managed. If you don’t already have an Azure resource group, you can create a new one with the New-AzResourceGroup cmdlet.

The following example creates a resource group named myResourceGroup in the West US 2 region:

Create a storage account

A storage account is a shared pool of storage you can use to deploy Azure file shares. A storage account can contain an unlimited number of shares, and a share can store an unlimited number of files, up to the capacity limits of the storage account. This example creates a general purpose version 2 (GPv2 storage account), which can storage standard Azure file shares or other storage resources such as blobs or queues, on hard-disk drive (HDD) rotational media. Azure Files also supports premium solid-state disk drives (SSDs); premium Azure file shares can be created in FileStorage storage accounts.

This example creates a storage account using the New-AzStorageAccount cmdlet. The storage account is named mystorageaccount and a reference to that storage account is stored in the variable $storageAcct. Storage account names must be unique, so use Get-Random to append a number to the name to make it unique.

Shares greater than 5 TiB (up to a maximum of 100 TiB per share) are only available in locally redundant (LRS) and zone redundant (ZRS) storage accounts. To create a geo-redundant (GRS) or geo-zone-redundant (GZRS) storage account, remove the -EnableLargeFileShare parameter.

Create an Azure file share

Now you can create your first Azure file share. You can create a file share using the New-AzRmStorageShare cmdlet. This example creates a share named myshare .

Share names need to be all lower-case letters, numbers, and single hyphens but cannot start with a hyphen. For complete details about naming file shares and files, see Naming and Referencing Shares, Directories, Files, and Metadata.

Use your Azure file share

Azure Files provides two methods of working with files and folders within your Azure file share: the industry standard Server Message Block (SMB) protocol and the File REST protocol.

To mount a file share with SMB, see the following document based on your OS:

Using an Azure file share with the File REST protocol

It is possible work with the File REST protocol directly (i.e. handcrafting REST HTTP calls yourself), but the most common way to use the File REST protocol is to use the Azure PowerShell module, the Azure CLI, or an Azure Storage SDK, all of which provide a nice wrapper around the File REST protocol in the scripting/programming language of your choice.

In most cases, you will use your Azure file share over the SMB protocol, as this allows you to use the existing applications and tools you expect to be able to use, but there are several reasons why it is advantageous to use the File REST API rather than SMB, such as:

  • You are browsing your file share from the PowerShell Cloud Shell (which cannot mount file shares over SMB).
  • You are taking advantage of serverless resources, such as Azure Functions.
  • You are creating a value-add service that will interact with many Azure file shares, such as performing backup or antivirus scans.

The following examples show how to use the Azure PowerShell module to manipulate your Azure file share with the File REST protocol. The -Context parameter is used to retrieve the storage account key to perform the indicated actions against the file share. To retrieve the storage account key, you must have the Azure role of Owner on the storage account.

Create directory

To create a new directory named myDirectory at the root of your Azure file share, use the New-AzStorageDirectory cmdlet.

Upload a file

To demonstrate how to upload a file using the Set-AzStorageFileContent cmdlet, we first need to create a file inside your PowerShell Cloud Shell’s scratch drive to upload.

This example puts the current date and time into a new file on your scratch drive, then uploads the file to the file share.

If you’re running PowerShell locally, you should substitute

/CloudDrive/ with a path that exists on your machine.

After uploading the file, you can use Get-AzStorageFile cmdlet to check to make sure that the file was uploaded to your Azure file share.

Download a file

You can use the Get-AzStorageFileContent cmdlet to download a copy of the file you just uploaded to the scratch drive of your Cloud Shell.

After downloading the file, you can use the Get-ChildItem to see that the file has been downloaded to your PowerShell Cloud Shell’s scratch drive.

Copy files

One common task is to copy files from one file share to another file share. To demonstrate this functionality, you can create a new share and copy the file you just uploaded over to this new share using the Start-AzStorageFileCopy cmdlet.

Now, if you list the files in the new share, you should see your copied file.

While the Start-AzStorageFileCopy cmdlet is convenient for ad hoc file moves between Azure file shares, for migrations and larger data movements, we recommend robocopy on Windows and rsync on macOS and Linux. robocopy and rsync use SMB to perform the data movements instead of the FileREST API.

Create and manage share snapshots

One additional useful task you can do with an Azure file share is to create share snapshots. A snapshot preserves a point in time for an Azure file share. Share snapshots are similar to operating system technologies you may already be familiar with such as:

You can create a share snapshot for a share by using the Snapshot method on PowerShell object for a file share, which is retrieved with the Get-AzStorageShare cmdlet.

Browse share snapshots

You can browse the contents of the share snapshot by passing the snapshot reference ( $snapshot ) to the -Share parameter of the Get-AzStorageFile cmdlet.

List share snapshots

You can see the list of snapshots you’ve taken for your share with the following command.

Restore from a share snapshot

You can restore a file by using the Start-AzStorageFileCopy command we used before. For the purposes of this quickstart, we’ll first delete our SampleUpload.txt file we previously uploaded so we can restore it from the snapshot.

Delete a share snapshot

You can delete a share snapshot by using the Remove-AzStorageShare cmdlet, with the variable containing the $snapshot reference to the -Share parameter.

Clean up resources

When you are done, you can use the Remove-AzResourceGroup cmdlet to remove the resource group and all related resources.

You can alternatively remove resources one by one:

To remove the Azure file shares we created for this quickstart.

You must delete all the share snapshots for the Azure file shares you created before deleting the Azure file share.

To remove the storage account itself (this will implicitly remove the Azure file shares we created as well as any other storage resources you may have created such as an Azure Blob storage container).

Читайте также:  Базовые элементы интерфейса windows
Оцените статью