none
Add Virtual Application and Directory to an Azure Website using Powershell

    Question

  • hi,

    I want to use remote powershell command to create a virtual directory in Azure website and map it to a folder in Azure site.

    Also i want to create a virtual application on azure site and upload a application package.

    All these i want by using remote Azure powershell.


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Friday, December 12, 2014 9:23 AM

Answers

  • You are not running the correct command, and that's probably true of your Set-AzureResource too, which explains why it doesn't work. You are using the command for the site info, and not the site config info (yes, they're two different things. I know, confusing!).

    Please see my response above for the correct way to use Set-AzureResource, and use the exact same pattern (e.g. notice the -ParentResource flag).

    I guarantee you this will work :)

    David

    Wednesday, December 17, 2014 6:49 PM
    Moderator

All replies

  • hi Nikhil,

    I assume this is not in context of a Virtual Machine, but regular websites. if my understanding is correct.

    there is a good set of Azure Cmdlets that lets you do anything (mostly) with Azure Websites.

    run the "get-help website" powershell command. it shows entire list of available commands for websites.

    also take a look at this short channel 9 video from Brady Gaster.

    hope this helps

    ----------------------------

    Please mark as answered if it helped


    Vishal Narayan Saxena http://twitter.com/vishalishere http://www.ogleogle.com/vishal/

    • Proposed as answer by vishalishereMVP Friday, December 12, 2014 2:26 PM
    • Unproposed as answer by Nikhil ahuja Friday, December 12, 2014 4:48 PM
    Friday, December 12, 2014 2:26 PM
  • Hi vishal,

    thanks for your reply. but i have already gone through those command and none of them was able to solev my problem

    The closest one i reach is 

    http://msdn.microsoft.com/en-us/library/azure/dn495207.aspx

    Set-AzureWebsite [[-Name] <String> ] [[-SiteWithConfig] <SiteWithConfig> ] [-AppSettings <Hashtable> ] [-ConnectionStrings <ConnStringPropertyBag> ] [-DefaultDocuments <String[]> ] [-DetailedErrorLoggingEnabled <Boolean> ] [-HandlerMappings <HandlerMapping[]> ] [-HostNames <String[]> ] [-HttpLoggingEnabled <Boolean> ] [-ManagedPipelineMode <ManagedPipelineMode> ] [-Metadata <List<NameValuePair>> ] [-NetFrameworkVersion <String> ] [-NumberOfWorkers <Int32> ] [-PassThru] [-PhpVersion <String> ] [-RequestTracingEnabled <Boolean> ] [-RoutingRules <List<RoutingRule>> ] [-Slot <String> ] [-WebSocketsEnabled <Boolean> ] [ <CommonParameters>]
    

    which can add handler mapping and other things but in this command also i am unable to set virtual directories.

    So i was hoping there is something which i don't know.

    May be Microsoft have not release command to set virtual directories.



    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Friday, December 12, 2014 4:50 PM
  • It's not ideal, but if you have access to Azure's REST APIs you can set it by sending a GET request to the following endpoint

    https: //management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/config/web

    You will get a JSON object back that represent your config, something like what’s below:

    {
        "properties": {
             // A bunch of properties will be here it's crucial to round-trip them 
            // otherwise you will blow all your config settings away
             [................................]
            "virtualApplications": [
                {
                    "virtualPath": "/",
                    "physicalPath": "site\\wwwroot",
                    "preloadEnabled": false,
                    "virtualDirectories": null
                },
                {
                    "virtualPath": "/project2",
                    "physicalPath": "site\\project2",
                    "preloadEnabled": false,
                    "virtualDirectories": null
                },
                {
                    "virtualPath": "/project3",
                    "physicalPath": "site\\project3",
                    "preloadEnabled": false,
                    "virtualDirectories": null
                }
            ],
             // A bunch of properties will be here it's crucial to round-trip them 
            // otherwise you will blow all your config settings away
             [................................]
        }
    }

    Add or remove objects to the virtualApplications collection, and send that whole config object in a PUT request to the same URL above.


    • Edited by Zain Rizvi Friday, December 12, 2014 6:36 PM
    Friday, December 12, 2014 6:35 PM
  • I think there is a way to do it using PowerShell if you use AzureResourceManager mode, but using the lower level Set-AzureResource. If you're interested in that approach, I can come up with a sample. It will look a little complicated, but should be functional.
    Friday, December 12, 2014 6:51 PM
    Moderator
  • Hi David,

    I tried using these command but i am getting error. it would be great if you can come up with some sample as you mentioned.

    @Zain I wanted it to be a powershell solution but if were not able to solve it than i will definatly try your solution also.

    Thanks to both of you.



    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Friday, December 12, 2014 7:55 PM
  • Ok, here it comes!

    First, define the properties you want to set, much like in Zain's reply except with PowerShell syntax. e.g.

    $props = @{
      "virtualApplications" = @(
        @{
          "virtualPath" = "/";
          "physicalPath"= "site\wwwroot";
        },
        @{
          "virtualPath" = "/foo";
          "physicalPath"= "site\bar";
        }
      )
    }

    And now run Set-AzureResource as follows:

    Set-AzureRmResource -ResourceGroupName MyResGroup -ResourceType Microsoft.Web/sites/config -ResourceName hackit/web -PropertyObject $props -ApiVersion 2015-08-01




    Friday, December 12, 2014 8:40 PM
    Moderator
  • hi David,

    Thanks for making efforts but still no success

    I tried your command it executes without error but nothing happened.

    After executing command when i go to portal i cannot see virtual directories created there.

    Also i tested one more thing 

    I created a virtual directory manually from portal

    i executed the 

    Switch-AzureMode -Name AzureResourceManager
    
    Get-AzureResource -ResourceGroupName MyResGroup -ResourceType Microsoft.Web/sites Name web -ParentResource sites/MySite -ApiVersion 2014-11-01

    and there is no property returned from power shell which contains virtual directory path.

    is it that it cannot be done???

    P.S. in above commands you specified -ResourceType Microsoft.Web/sites/config it error out with resource cannot be found i changed it to -ResourceType Microsoft.Web/sites than it works.


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Saturday, December 13, 2014 5:42 AM
  • hi Nikhil,

    Please ensure you are running powershell scripts in context of your subscription (generally the most overlooked cause)

    ~Vishal


    Vishal Narayan Saxena http://twitter.com/vishalishere http://www.ogleogle.com/vishal/

    Monday, December 15, 2014 10:51 PM
  • Hi Nikhil,

    What exactly are you getting back when you call Get-AzureResource? On a brand new site, you should get something like this, which includes a virtualApplications property:

     {
       "numberOfWorkers": 1,
       "defaultDocuments": [
         "Default.htm",
         "Default.html",
         "Default.asp",
         "index.htm",
         "index.html",
         "iisstart.htm",
         "default.aspx",
         "index.php",
         "hostingstart.html"
       ],
       "netFrameworkVersion": "v4.0",
       "phpVersion": "5.4",
       "pythonVersion": "",
       "requestTracingEnabled": false,
       "requestTracingExpirationTime": null,
       "remoteDebuggingEnabled": false,
       "remoteDebuggingVersion": null,
       "httpLoggingEnabled": false,
       "logsDirectorySizeLimit": 35,
       "detailedErrorLoggingEnabled": false,
       "publishingUsername": "$TmpTestVDirs",
       "publishingPassword": null,
       "appSettings": null,
       "metadata": null,
       "connectionStrings": null,
       "handlerMappings": null,
       "documentRoot": null,
       "scmType": "None",
       "use32BitWorkerProcess": true,
       "webSocketsEnabled": false,
       "alwaysOn": false,
       "javaVersion": null,
       "javaContainer": null,
       "javaContainerVersion": null,
       "managedPipelineMode": 0,
       "virtualApplications": [
         {
           "virtualPath": "/",
           "physicalPath": "site\\wwwroot",
           "preloadEnabled": false,
           "virtualDirectories": null
         }
       ],
       "winAuthAdminState": 0,
       "winAuthTenantState": 0,
       "customAppPoolIdentityAdminState": true,
       "customAppPoolIdentityTenantState": false,
       "runtimeADUser": null,
       "runtimeADUserPassword": null,
       "loadBalancing": 1,
       "routingRules": [],
       "experiments": {
         "rampUpRules": []
       },
       "limits": null,
       "autoHealEnabled": false,
       "autoHealRules": null,
       "tracingOptions": null,
       "vnetName": "",
       "siteAuthEnabled": false,
       "siteAuthSettings": null,
       "autoSwapSlotName": null
     }


    Tuesday, December 16, 2014 7:23 PM
    Moderator
  • hi David,

    i created a new site and still i am not getting 

      "virtualApplications": [
         {
           "virtualPath": "/",
           "physicalPath": "site\\wwwroot",
           "preloadEnabled": false,
           "virtualDirectories": null
         }

    tags.


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Tuesday, December 16, 2014 7:40 PM
  • Are you getting everything except for that property? Can you paste the full output? Also, can you share the name of your test site?
    Tuesday, December 16, 2014 7:42 PM
    Moderator
  • hi David,

    yes i am getting everything except virtual directories

    test site name name

    http://nikhiltest.azurewebsites.net

    PS C:\svn> Switch-AzureMode -Name AzureResourceManager
    PS C:\svn> Get-AzureResource -ResourceGroupName Default-Web-SoutheastAsia -ResourceType Microsoft.Web/sites -Name Nikhil
    Test -ApiVersion 2014-11-01


    Name              : NikhilTest
    ResourceGroupName : Default-Web-SoutheastAsia
    ResourceType      : Microsoft.Web/sites
    ParentResource    :
    Location          : Southeast Asia
    Properties        : {
                          "name": "NikhilTest",
                          "state": "Running",
                          "hostNames": [
                            "nikhiltest.azurewebsites.net"
                          ],
                          "webSpace": "SoutheastAsiawebspace",
                          "selfLink": "https://waws-prod-sg1-001.api.azurewebsites.windows.net:454/subscriptions/0ac22b8d-f
                        661-44a1-89ef-ed5456703522/webspaces/SoutheastAsiawebspace/sites/NikhilTest",
                          "repositorySiteName": "NikhilTest",
                          "owner": null,
                          "usageState": 0,
                          "enabled": true,
                          "adminEnabled": true,
                          "enabledHostNames": [
                            "nikhiltest.azurewebsites.net",
                            "nikhiltest.scm.azurewebsites.net"
                          ],
                          "siteProperties": {
                            "metadata": null,
                            "properties": [],
                            "appSettings": null
                          },
                          "availabilityState": 0,
                          "sslCertificates": null,
                          "csrs": [],
                          "cers": null,
                          "siteMode": null,
                          "hostNameSslStates": [
                            {
                              "name": "nikhiltest.azurewebsites.net",
                              "sslState": 0,
                              "ipBasedSslResult": null,
                              "virtualIP": null,
                              "thumbprint": null,
                              "toUpdate": null,
                              "toUpdateIpBasedSsl": null,
                              "ipBasedSslState": 0,
                              "hostType": 0
                            },
                            {
                              "name": "nikhiltest.scm.azurewebsites.net",
                              "sslState": 0,
                              "ipBasedSslResult": null,
                              "virtualIP": null,
                              "thumbprint": null,
                              "toUpdate": null,
                              "toUpdateIpBasedSsl": null,
                              "ipBasedSslState": 0,
                              "hostType": 1
                            }
                          ],
                          "computeMode": null,
                          "serverFarm": "Default1",
                          "webHostingPlan": "Default1",
                          "lastModifiedTimeUtc": "2014-12-16T19:38:52.737",
                          "storageRecoveryDefaultState": "Running",
                          "contentAvailabilityState": 0,
                          "runtimeAvailabilityState": 0,
                          "siteConfig": null,
                          "deploymentId": "NikhilTest",
                          "trafficManagerHostNames": null,
                          "sku": "Standard",
                          "premiumAppDeployed": null,
                          "scmSiteAlsoStopped": false,
                          "targetSwapSlot": null,
                          "hostingEnvironment": null,
                          "microService": "WebSites",
                          "cloningInfo": null
                        }
    Tags              :
    Permissions       :
                        Actions  NotActions
                        =======  ==========
                        *

    ResourceId        : /subscriptions/0ac22b8d-f661-44a1-89ef-ed5456703522/resourceGroups/Default-Web-SoutheastAsia/provid
                        ers/Microsoft.Web/sites/NikhilTest


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Wednesday, December 17, 2014 3:45 AM
  • You are not running the correct command, and that's probably true of your Set-AzureResource too, which explains why it doesn't work. You are using the command for the site info, and not the site config info (yes, they're two different things. I know, confusing!).

    Please see my response above for the correct way to use Set-AzureResource, and use the exact same pattern (e.g. notice the -ParentResource flag).

    I guarantee you this will work :)

    David

    Wednesday, December 17, 2014 6:49 PM
    Moderator
  • hi David,

    Thank you so much for this. Yes it worked as you said. I was doing silly mistakes on my behalf.

    Thanks again.


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Wednesday, December 17, 2014 7:36 PM
  • This is all good and well. But what do we do when the AzureResourceManager is deprecated?
    Monday, July 13, 2015 12:30 PM
  • Coderpews: AzureResourceManager is the new API, so it will be around for years. And you get to specify the version, making sure that API changes don't break you.
    Thursday, July 23, 2015 1:32 AM
    Moderator
  • Hi Nikhil,

    I am facing same issue. can you please share the working command for get-resource.

    Thursday, September 03, 2015 9:32 AM
  • You can use the PowerShell tab on https://resources.azure.com/ to get the correct Get-AzureResource command for any resource.
    Thursday, September 03, 2015 10:50 PM
    Moderator
  • That helped me a lot. 

    Monday, September 07, 2015 11:08 AM
  • my command

    Set-AzureResource -ResourceGroupName "Default-Web-NorthEurope" -ResourceType "Microsoft.Web/sites/config" `
      -Name "WebPortal-mit005" -ParentResource "sites/WebPortal-mit005" -PropertyObject $props -ApiVersion 2014-11-01

    returns

    Set-AzureResource :
    At line:2 char:3
    +   Set-AzureResource -ResourceGroupName "Default-Web-NorthEurope" -ResourceType " ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : CloseError: (:) [Set-AzureResource], ErrorResponseMessageException
        + FullyQualifiedErrorId : NotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourc
       eCmdlet

    Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException

    I do think I am following your sample.

    Thanks


    FT

    Tuesday, September 15, 2015 1:29 AM
  • Hi Frederic, Please use the link David shared to build any azure cmd. In your case i see that cmd is not found you have to switch the mode to azure resource manager to ge this cmds.

    Switch-AzureMode -Name AzureResourceManager

    Try it.

    Tuesday, September 15, 2015 8:52 AM
  • I used the web site https://resources.azure.com to find the right powershell code to create virtual folders.

    it worked but it is different from this answers in this page.

    What is the api to now deploy my web deploy package to a sub virtual directory?

    Thanks.


    FT

    Wednesday, September 16, 2015 1:28 AM
  • Use the one from Resource Explorer, which is the newer/better one (-ParentResource is obsolete).

    The WebDeploy question is mostly unrelated to the primary topic of this thread, and would be better asked in a separate thread to avoid mixing the two topics.

    Wednesday, September 16, 2015 1:37 AM
    Moderator
  • Hi David Ebbo,

    I want to Add Virtual applications and directories to an Azure Website using PowerShell.
    Currently it is doing manually.
    I tried the things which you have mention in the article but I'm unable to get the things working.
    Could you please help for complete my requirement.

    Thanks.


    Monday, May 16, 2016 12:09 PM
  • @venuja, please clarify the full command that you are running, and the exact output that you are getting.

    David

    Monday, May 16, 2016 3:11 PM
    Moderator
  • Hi David Ebbo,

    I want to add “site\wwwroot\Frontend” as my virtual path because our web application start up page is located inside Frontend.

    [img]http://i.imgur.com/uTfiMUe.png?1[/img]

    Could you please provide me PowerShell command to complete this requirement.

    Thanks.
    Thursday, May 19, 2016 4:31 AM
  • @Venuja: please see my answer above that starts with "Ok, here it comes". You should be able to do something along those lines.
    Thursday, May 19, 2016 2:42 PM
    Moderator
  • I wrote a blog post about developing a TFS/VSTS task that deploys to a virtual app.  You may be able to use this task or just view the source PowerShell as an example.

    http://www.dotnetcatch.com/2016/03/22/vsts-release-custom-deploy-task-to-deploy-virtual-applications-to-azure/


    Follow me on Twitter - @chief7

    Friday, May 20, 2016 11:03 AM
  • Hi David Ebbo,

    Thanks for the help.That works :)

    Thanks.

    Wednesday, May 25, 2016 2:53 AM