Azure Azure Cloud Shell Azure PowerShell

Upload and run an Azure PowerShell script from your clouddrive in Azure Cloud Shell


In this blog post, I will show you how you can upload and run Azure PowerShell scripts from your clouddrive in Azure Cloud Shell.

Azure Cloud Shell is an interactive browser-accessible shell for managing Azure resources with PowerShell or Bash, and this directly form within a browser, Windows Terminal, Visual Studio Code or the Azure Mobile App.

When you start up a new Azure Cloud Shell, Azure creates a Linux container image which it stores in a storage account.



Good to know for all who is using Cloud Shell for the first time, is that it will prompt you to create a resource group, storage account, and an Azure Files share, as a one-time process. If you want to automate and govern this setup process you can read my blog post about how to Setup Azure Cloud Shell with Azure PowerShell


Azure Cloud Shell uses an Azure file share to securely store your data files. This file share, labeled clouddrive, is mounted in your Cloud Shells $home directory (/home/<username>/clouddrive) and is mapped to fileshare.storage.windows.net/fileshare for direct file-share interaction.

The $home directory (disk image) itself is an .img file (acc_<username>.img) which automatically persists data in this specified file share (fileshare.storage.windows.net/fileshare/.cloudconsole/acc_<username>.img) and automatically syncs changes.







You can run the Get-CloudDrive PowerShell cmdlet, to see all settings of the clouddrive and to find useful information like the FileSharePath and the MountPoint.


Upload an Azure PowerShell script (or other file) to your clouddrive

Azure Cloud Shell gives you great flexibility and is excellent for saving and running a script from anywhere, without any dependencies of the device your working one.

So, next to managing Azure resources it also allows you to easily upload (and download) all types of files and even folders, which when uploaded you can then use for any kind of Azure operational task.

To start, open your Microsoft Edge or other preferred web browser. You can use Cloud Shell directly from inside the Azure portal by clicking on the Cloud Shell icon, which then will open a new frame at the bottom of the screen. Or you can browse to the direct link in a (new) tab https://shell.azure.com , where you then need to log in with your Azure account, if (still) required.




To upload a file click on the Upload/Download files icon in the Cloud Shell toolbar, and then click Manage file share.

Keep in mind that if you select Upload instead of Manage file share the selected script or file will be uploaded in the $home directory (/home/<username>), and not on your clouddrive. If you used Upload you can still move the script from your $home directory to your clouddrive afterwards with the following PowerShell cmdlet: Copy-Item ./<yourfile.ps1> /home/<username>/clouddrive -Verbose




If you want to store all your PowerShell script files underneath a dedicated folder you can create a new folder by selecting + Add directory.



Click on your newly created directory to open it, and then click on Upload to upload your PowerShell script (or other file).




Once the upload is complete, a notification is shown in the Notifications area.



Run an uploaded Azure PowerShell script from your clouddrive

You can now run the uploaded or an existing script by opening the clouddrive and then the newly created folder (in my case the PowerShell folder).

cd clouddrive

cd <yourfolder>

When working with Cloud Shell, you can also use command-line commands, like cd and dir, to move between folders or to display a list of the files and subfolders contained in a folder.




If you want to edit your uploaded PowerShell script from inside Azure Cloud Shell you can use the built-in Azure Cloud Shell editor based on VS Code (not the full VS Code experience). To use this editor, type the code . command followed by the name of the script (or file) you want to edit.

code ./<scriptName.ps1>



Conclusion

Azure Cloud Shell offers a browser-based, cross-platform experience which gives you access to powerful tools to manage your Azure resources. Next to those management capabilities, it also foresees a clouddrive where you can store all kind of files and scripts, which you can then run, use or edit from anywhere. In this blog post I showed you how you can upload, run and even edit an Azure PowerShell script from your clouddrive in Azure Cloud Shell.


1 comment on “Upload and run an Azure PowerShell script from your clouddrive in Azure Cloud Shell

  1. Pingback: Setup Azure Cloud Shell with Azure PowerShell – Wim Matthyssen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: