How to create a virtual directory in an Azure Web application using PowerShell

In the cloud computing era, creating an IIS virtual directory in PowerShell only required running the `New-WebVirtualDirectory` command. Nowadays, things are done a little differently. Perhaps someday well use the `New-AzureWebVirtualDirectory` command in the Azure PowerShell module. However, until then, youll need to create your own virtual directory. This article from TipsMake will guide you on how to create a virtual directory in your Azure Web application using PowerShell.

The process of creating and assigning a virtual directory to an Azure Web application involves the following three steps:

1. Retrieve the Microsoft.Azure.Management.WebSites.Models.Site object.

2. Create object Microsoft.Azure.Management.WebSites.Models.VirtualApplication.

3. Assign the VirtualApplication object to the Site object.

How to create a virtual directory in an Azure Web application using PowerShell

There's a bit of a problem with .NET objects when creating virtual directories, so to fix this and create a script, follow these steps:

First, ensure you have installed the latest AzureRm PowerShell module (Install-Module -Name AzureRm). After downloading the latest AzureRm PowerShell module, the next step is to retrieve your web application to mount the virtual directory. You can use Get-AzureRmWebApp to do this by specifying the resource group it belongs to and the name of your web application.

$webApp = Get-AzureRmWebApp -Name $AzureWebAppName -ResourceGroupName $AzureResourceGroup

The next step is to create a VirtualApplication object. This object has three properties you need to pay attention to: VirtualPath , PhysicalPath , and PreloadEnabled (optional). The VirtualPath and PhysicalPath properties are displayed in the Azure Web portal if you view the Application Settings of a web application.

This VirtualApplication object is created from the Microsoft.Azure.Management.WebSites.Models.VirtualApplication class and has the properties mentioned above set.

$virtApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication

$virtApp.VirtualPath = $VirtualPath

$virtApp.PhysicalPath = $PhysicalPath

$virtApp.PreloadEnabled = $PreloadEnabled

After the VirtualApplication object is created, the next step is to assign it to your web application. The Microsoft.Azure.Management.WebSites.Models.Site object returned from Get-AzureRmWebApp contains a siteconfig property.

This project contains a VirtualApplications property with an Add() method that accepts the Microsoft.Azure.Management.WebSites.Models.VirtualApplication object. You can use this Add() method to pass the VirtualApplication object you just created to your web application.

$null = $webApp.siteconfig.VirtualApplications.Add($virtApp)

So you've just created a virtual directory and added it to your local Web application. The next step is to commit your changes to the Azure Web application using the `Set-AzureRmWebApp` command . Since the `$webApp` variable already has the virtual directory attached, you can overwrite the existing file with the modified object.

Set-AzureRmWebApp -WebApp $webApp

Now that you have all the code built to mount a virtual directory to your Azure Web application, you can roll all this code into a single parameterized script and no longer have to worry about it. This script (or function) will reside in the Azure Web repository.

The article on TipsMake just showed you how to create a virtual directory in an Azure Web application using PowerShell.


As you can see, PowerShell's capabilities are vast. Not only is it available on Azure Web, but PowerShell is also integrated into Windows 10, allowing users to perform many tasks such as backing up drivers on Windows 10 using PowerShell . If you have any questions or need clarification, please leave your comments in the section below the article.

Other Advice Computer articles
  • Back up DVD/CD/VCD discs to ISO using UltraISO.

    ultraiso is a very powerful iso creation software for computers. with it, we can easily back up dvd/cd/vcd discs to iso, create virtual drives, or burn discs. let's explore how to back up a dvd disc to iso using ultraiso in the article below.
  • Should you choose Dual Boot or Virtual Machine?

    suppose for some reason you want to run two operating systems on your computer. there are two ways to run multiple operating systems on one computer: dual boot and virtual machine. if you're wondering whether to choose dual boot or virtual machine, please refer to the article below from tipsmake.
  • The simplest way to sign up for Azure.

    sign up for azure today to get a free cloud account and enjoy most of the services available in azure, such as virtual machines, sql databases, hadoop, mobile advertising, online media, active directory, and more.
  • What is a virtual machine? What are the uses of virtual machines on a computer?

    the use of virtual machines is essential for individuals and companies working in programming and information technology. virtual machine features include virus scanning, enhanced server security, and software testing.
  • Create a virtual machine on a USB drive with VirtualBox.

    tipsmake will share a guide on creating virtual machines on a usb drive using virtualbox in the following article, so you can use virtualbox to create virtual machines effectively, allowing you to create virtual machines that run smoothly on your operating system.
  • How to use dual-monitor display mode on VMware

    vmware is software that allows us to emulate current operating system environments, and users can also use two monitors on vmware if needed. the following guide will help you enable it.
Category

System

Windows XP

Windows Server 2012

Windows 8

Windows 7

Windows 10

Wifi tips

Virus Removal - Spyware

Speed ​​up the computer

Server

Security solution

Mail Server

LAN - WAN

Ghost - Install Win

Fix computer error

Configure Router Switch

Computer wallpaper

Computer security

Mac OS X

Mac OS System software

Mac OS Security

Mac OS Office application

Mac OS Email Management

Mac OS Data - File

Mac hardware

Hardware

USB - Flash Drive

Speaker headset

Printer

PC hardware

Network equipment

Laptop hardware

Computer components

Advice Computer

Game

PC game

Online game

Mobile Game

Pokemon GO

information

Technology story

Technology comments

Quiz technology

New technology

British talent technology

Attack the network

Artificial intelligence

Technology

Smart watches

Raspberry Pi

Linux

Camera

Basic knowledge

Banking services

SEO tips

Science

Strange story

Space Science

Scientific invention

Science Story

Science photo

Science and technology

Medicine

Health Care

Fun science

Environment

Discover science

Discover nature

Archeology

Life

Travel Experience

Tips

Raise up child

Make up

Life skills

Home Care

Entertainment

DIY Handmade

Cuisine

Christmas

Application

Web Email

Website - Blog

Web browser

Support Download - Upload

Software conversion

Social Network

Simulator software

Online payment

Office information

Music Software

Map and Positioning

Installation - Uninstall

Graphic design

Free - Discount

Email reader

Edit video

Edit photo

Compress and Decompress

Chat, Text, Call

Archive - Share

Electric

Water heater

Washing machine

Television

Machine tool

Fridge

Fans

Air conditioning

Program

Unix and Linux

SQL Server

SQL

Python

Programming C

PHP

NodeJS

MongoDB

jQuery

JavaScript

HTTP

HTML

Git

Database

Data structure and algorithm

CSS and CSS3

C ++

C #

AngularJS

Mobile

Wallpapers and Ringtones

Tricks application

Take and process photos

Storage - Sync

Security and Virus Removal

Personalized

Online Social Network

Map

Manage and edit Video

Data

Chat - Call - Text

Browser and Add-on

Basic setup