PowerShell File Processing

PowerShell Read File Contents

By: Stephen Patrick | 10 Jul 2016 | Category: PowerShell File Processing

PowerShell Read File Contents

PowerShell offers a number of cmdlets for working with files. Sometimes we may need to retrieve the contents of file, to display it, or process it. PowerShell provides a number of different ways to access the contents of a file. Let’s say we have a file called text.txt in the current directory. The file contains the following:

Read More

PowerShell Search File For Pattern

By: Stephen Patrick | 10 Jul 2016 | Category: PowerShell File Processing

PowerShell Search File For Pattern

PowerShell provides functionality to search the contents of one or more files for a pattern. The Select-String cmdlet enables us to achieve this goal.

Read More

PowerShell Searching With Regular Expressions

By: Stephen Patrick | 10 Jul 2016 | Category: PowerShell File Processing

PowerShell Searching With Regular Expressions

Regular expressions provide a powerful mechanism to search a file for text that has a particular pattern. We can use a regular expression to define a particular pattern. For example, we can define a regular expression to match a phone number, email, Uniform Resource Locator (URL) etc. We can define a regular expression to match a piece of text.

Read More

PowerShell: Search And Replace

By: Stephen Patrick | 10 Jul 2016 | Category: PowerShell File Processing

PowerShell: Search And Replace

We can use PowerShell to search for text and replace it in one or more files. We can use the Set-Content and the replace operator to achieve this. Let’s take a look at an example of replacing line numbers from a file with PowerShell.

Read More

PowerShell: Creating Files

By: Stephen Patrick | 13 Jul 2016 | Category: PowerShell File Processing

PowerShell: Creating Files

Sometimes we find the need to create files. We can create files with PowerShell. There are a number of different ways to create a file. We will look at some of the mechanisms here.

Read More

PowerShell: File Comparison

By: Stephen Patrick | 19 Jul 2016 | Category: PowerShell File Processing

PowerShell: File Comparison

A very common task is to compare two files for differences. We may perform this task as part of a post install verification process. PowerShell provides a couple of Cmdlets that aid with this activity.

Read More

PowerShell: Find Files Modified After Date

By: Stephen Patrick | 27 Jul 2016 | Category: PowerShell File Processing

PowerShell: Find Files Modified After Date

We can use PowerShell to find files modified after a certain date. This task can be useful to find recently modified files on a system. We can use the Get-ChildItem cmdlet to perform this task. The Get-ChildItem CmdLet provides the Recurse parameter which allows us to search in child directories.

Read More

PowerShell: Monitor Files For Changes

By: Stephen Patrick | 28 Jul 2016 | Category: PowerShell File Processing

PowerShell: Monitor Files For Changes

We can use PowerShell to monitor files for changes. The Get-Content Cmdlet provides the Wait parameter. The wait parameter will monitor the end of a file for any changes. This task can be useful in a number of situations such as monitoring a log file for changes.

Read More