PowerShell Set-Content

PowerShell Script Files: Set-Content Cmdlet

I don’t use Set-Content very often; this is because for routine tasks that need to save content to a file I prefer to use Out-File. The one job that I have for the Set-Content cmdlet is editing a file with -Replace. What makes me wary of Set-Content is that instead of appending, its default behaviour is to delete the contents of a file.

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Research Set-Content Parameters

Checking the help file will reveal useful parameters, for instance you can employ the -Force parameter to overwrite read-only files. Reading the help file also reveals that this command is primarily used for writing text to multiple files, perhaps this is why I am wary of using it myself, and avoid recommending this particular cmdlet to others.

Research PowerShell Alias ‘Sc’

With Microsoft, there are always at least three ways of doing everything, what seems like redundancy when you are an expert, seems like perspective when you are a beginner.

# PowerShell Alias AcGet-Alias -definition Set-Content

Another example of an alias is that you can abbreviate Format-Table to ft. As you increase your range of PowerShell commands, keep an eye out for another PowerShell Alias, for instance gci (Get-Childitem).

Summary of PowerShell’s Set-Content Cmdlet

In VBScript dealing with files was never straightforward. However, with PowerShell it’s so effortless that you may not realize that the Set-Content cmdlet opens and closes as part of its job description.

Set-Content is a simple enough cmdlet to understand. What it does is write text to files. Just playing with Set-Content leads to questions such as ‘Why bother’, or ‘What’s the point?’ I hope that your answer to such questions will give you a PowerShell technique that you can incorporate in bigger more complex scripts.