March 2, 2010

Powershell Grep to find old server names in batchfiles

Filed under: Script,Uncategorized — Tags: — Kevmar @ 11:40 am

I was troubleshooting a user access problem today and found that they had a old mapping to an old server in the login script.  We just moved all our data to a different server so it was expected to have a few issues like this.  We do use DFS for most of our shares so the transition was very smooth for most people.  Just a few exceptions needed fixed.

I think we just over looked the log in scripts so I needed a script to check them all.  This is where I should just use grep but I wanted to see how to do it in powershell.  Here is the command I came up with:

PS> get-childitem \\domain\netlogon -include *.bat -recurse | select-string "oldserver"

Here is another way to do the same thing with a few shorcuts that could be easier to remember at the command line:

PS> cd \\domain\netlogon
PS> dir -recurse | select-string "oldserver"

dir is short for get-childitem.  If all you have are .bat files in netlogon you can skip the include.  If you have other install files or packages, use the include to save time.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress