locked
How to use xml file as config file to store sql connection string and use it in powershell RRS feed

  • Question

  • Hi All,

    How can we use the xml file to configure the sql server connection string details and use the config file to get the connection string details in powershell script through config file.

    Thanks.


    • Edited by Aravind 18 Wednesday, June 28, 2017 12:39 AM
    Wednesday, June 28, 2017 12:38 AM

All replies

  • PowerShell does not use "config" files.  It can have one but it is not really editable.

    Here is one way to do this:

    PS > $config = @{}
    PS > $config.Add('ConnectionString', 'Provider-xxxx;Server=zzzz; ... ')
    PS > $config | Export-CliXml config.CliXml
    PS > $config = Import-CliXml config.CliXml
    PS > $config.ConnectionString
    Provider-xxxx;Server=zzzz; ...

    You could put the import into your "profile.ps1" file.


    \_(ツ)_/

    Wednesday, June 28, 2017 1:10 AM
  • I am using one ps1 file where I have hardcode few things. so how I can get those values from txt or xml file while running the ps1 file?
    Wednesday, June 28, 2017 1:16 AM
  • I am using one ps1 file where I have hardcode few things. so how I can get those values from txt or xml file while running the ps1 file?

    I just posted a way to do that.  It is an XML file.


    \_(ツ)_/

    Wednesday, June 28, 2017 1:24 AM