Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

search for a specific string in web.config file

$
0
0

Hi
Is there a way we can search a specific word in web.config using powershell.
I have an entry of "user name" in the connection string. I want to find what the user name is and whether its a correct user name or not based on the criteria set in the script.

i believe its a simple matter of if statement but due to connection string i am unable to do this.

this is my connection string from web.config

    <connectionStrings>
    <add name="Membership" connectionString="Data Source=testdb;Initial Catalog=test;user   
    name=testUser;password=123456;MultipleActiveResultSets=true" 
    providerName="System.Data.SqlClient"/>
    </connectionStrings>

My criteria is. if user name -eq testUser write-host "correct user name" else "user name is incorrect"

This is the script which i am using

    $webConfig = 'C:\Users\test\web.config'
    $cfg = [xml](gc $webConfig)

Not sure how the if statement will work in searching the document and applying critera


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>