find all references to a server in web.config files with powershell

ls \\someserver\c$\inetpub\wwwroot -r -i web.config | Select-String "SomeMachineName"
Finds all files of a certain name and reports all line with the string. Very simple.
Sample Output
(80) C:\P\OS.svn -? ls \\webserver\c\inetpub\wwwroot -i web.config -r | Select-String "db-server"

\\webserver\c\inetpub\wwwroot\SomeApp\Web.config:72:    <add nam
e="foo" connectionString="Server=db-server;Database=foo;Integrated Security=true"/>
\\webserver\c\inetpub\wwwroot\SomeApp\Web.config:74:    <add nam
e="bar" connectionString="Server=db-server;Database=bar;Integrated Security=true"/>

By: cbilson
2009-03-25 22:36:58

What Others Think

I give Microsoft credit for making an effort to have a shell. Although the foreign syntax and commands are somewhat revolting to me: +1
bwoodacre · 617 weeks and 1 day ago
Powershell runs on Unix now? Why? Why not use sh, bash, or ksh, which are full featured, mature and robust? -1, since this is not a unix command.
ozymandias · 617 weeks and 1 day ago
Nobody said anything about this running on Unix. If you read the FAQ for this site, ALL shells are accepted.
kzh · 520 weeks and 1 day ago
+1 because unix snobs are voting this down
jrdld · 282 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: