locked
Web App add or modify Connection String via PowerShell RRS feed

  • Question

  • Hi,

    As I've checked from resources.azure.com and got the cmdlets shown below. 

    # SET list

    $PropertiesObject = @{

                #Property = value;

    }

    New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName MY-RG-NAME -ResourceType Microsoft.Web/sites/config -ResourceName MY-APP-NAME/connectionstrings -ApiVersion 2015-08-01 -Force

    I tried to add a DB connection string by running the modified ones shown below and got errors

    $PropertiesObject = @{

                Name = 'defaultConnection';

                Value = 'Data Source=tcp:mydbserver1.database.windows.net,1433;Initial Catalog=mydbservice1;User Id=mydbadmin@tcp:mydbserver1.database.windows.net;Password=my_db_password;';

                type = '2'

    }

    New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName MY-RG-NAME -ResourceType Microsoft.Web/sites/config -ResourceName MY-APP-NAME/connectionstrings -ApiVersion 2015-08-01 -Force

    As I need to add db connection strings to many web app,  seeking a way to do it in bulk.  Has anyone tried to do this before?

    Regards.


    Sunday, December 11, 2016 5:24 PM

Answers

  • Hi,

    >I tried to add a DB connection string by running the modified ones shown below and got errors

    This error caused by you defined the invalid value in $PropertiesObject. As my test we need to use below format:

    $PropertiesObject = @{
          "contst" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"}
                
    }

    If you have more than one connection string, please define all in above parameter:

    $PropertiesObject = @{
          "contst" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"};
       "contst2" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"}
                
    }

    Here is my result that shown in Azure portal:

    Please note, this powshell command will update the properties with the value you defined. If the value in Azure portal, but not in your $PropertiesObject, the value in Azure portal will be lost.

    Best Regards,

    Jambor


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, December 12, 2016 2:25 AM

All replies

  • Hi,

    >I tried to add a DB connection string by running the modified ones shown below and got errors

    This error caused by you defined the invalid value in $PropertiesObject. As my test we need to use below format:

    $PropertiesObject = @{
          "contst" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"}
                
    }

    If you have more than one connection string, please define all in above parameter:

    $PropertiesObject = @{
          "contst" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"};
       "contst2" = @{
                  value="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
                  type="2"}
                
    }

    Here is my result that shown in Azure portal:

    Please note, this powshell command will update the properties with the value you defined. If the value in Azure portal, but not in your $PropertiesObject, the value in Azure portal will be lost.

    Best Regards,

    Jambor


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, December 12, 2016 2:25 AM
  • Hi,

    Please check the blog post Windows Azure Web Sites: How Application Strings and Connection Strings Work for updating connection strings using Power Shell cmdlets incase if you have missed any steps.

    Let us know if that helps.

     

    Regards,

    Ashok

    Wednesday, December 14, 2016 11:02 AM
  • Hi Jambor, I'll check and let you know the result. Thank you.
    Wednesday, December 21, 2016 7:40 AM
  • Welcome back if you have any further issues. If my reply could help you, please mark it as answer.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 21, 2016 8:33 AM
  • Hello Jambor, I marked your post as answer.

    Thank you for your help.

    Regards.

    Friday, December 23, 2016 1:18 PM