How to Replace Text in Files with PowerShell

Code is developed on: Windows 10 Version 1703, Build 10.0.15063.138

In this short article I will show you how to replace a matched string in multiple files. In this use case I will search for Windows Media Player playlists on \\fileserver1\media\audio. Because we are implementing DFS Namespaces, the links inside the playlists needs to be changed to \\runas\dfs\media\audio.



  • Line 1: Collects the file information in the variable $wpls
  • Line 2: We start a foreach loop here. For every file object we execute the next action:
  • Line 3: For the file object we grab the contents, search for the string ‘fileserver1’ and replace this with ‘runas\dfs’. This will only change the values in the object. After we pipe this to Out-File to write it back to the original file.

Visual Studio Code Survival Guide for PowerShell Coders

In this series I will share information on how to use Microsoft’s Visual Studio Code for PowerShell coding. The article contains tips/tricks to be better able to use VS Code. It’s a personal log that I keep in my learning process for VS Code. Hopefully it helps you too!

Useful Links

Change the Default Language Mode to PowerShell

When you install VS Code, the default language mode for new files is set to plaintext. If you’re used to PowerShell ISE, this is quite annoying. In the way I work is that I open a new file, type my commands and then execute the code.

In VS Code you had to save the file first as a PowerShell file, or change the language mode before you could do this. David Wilson made it now possible to change this behaviour. He build in a new configuration setting called “files.defaultLanguage” which allows you to change the language mode for new, unsaved files.

Be carefull, that you specify the setting in lowercase powershell, otherwise it will not work.

The Importance of the PowerShell Community

I’m back home from spending the week at Hannover, at the PowerShell Conference Europe. This conference is all about PowerShell. It’s organized by Tobias Weltner, a true pioneer in the world of PowerShell. This conference took in initially 160 participants, and it was fully booked. Actually Tobias expanded to 200 delegates, and in the end there were around 250 people present! What a blast! With around 75 sessions, there was a lot of content to cover.

With speakers/IT rockstars like Bruce Payette, Jeffrey Snover, David Wilson, Hemant Mahawar, Jared Atkinson, Will Schroeder, Aleksandar Nikolić, Richard Siddaway, June Blender, Ravikanth Chaganti, and many more, this conference had the cremé-de-la-cremé of what the PowerShell community has to offer. Besides of the speakers there were many high skilled delegates, of which I had the privileged to meet.

To me, this was the very first time of attending a pure PowerShell conference. I went a few times to congresses like TechED and Techdays, but PowerShell Conference EU is for me the best till now. The feeling of community was so strong here; and this is why I write this post. I want to point out that YOUR success in your career will be highly boosted when you start to participate in the community.

I was for long time a ‘lurker’, and I didn’t contribute anything. A few months ago I decided to change this, and started to participate in mainly the forum, and answering questions and write some blog posts. Also I try to keep up a bit on the PowerShell section at Reddit and I’m sometimes active on the SLACK/IRC PowerShell channel.

My main reason for this is that I want to share what I know, and helping out people that are willing to take my help.

When you go to a conference like the PSCONFEU one, you really get the feeling that you’re doing something useful. With all the people that I talked with last week, it became clear to me that the people in the community really have PASSION for what they do. They don’t see IT as a job, it’s THE thing they really like, it’s their passion. Seeing people like Bruce Payette or June Blender talking about their work, and seeing the sparkles in their eyes when they do, is really inspiring. And because of that I thank the community.

The community makes it possible to get in contact with these highly skilled people, who love what they do. So my advice is, if you love what you do, if you want to share your passion, if you want to get in touch with passioned people, start to participate in the community. In the end it’s good for your career, but even better for your own happiness. I’m certainly happy that I started to be active!

Be active, don’t be a lurker!