Tag Archives: code

List lines from a text file

There may come a time when you want to display just a few lines from a text file. The following PowerShell code can be used to achieve this. The examples will be based upon a sample text file containing the … Continue reading

Posted in powershell | Tagged , | Leave a comment

Enumerating over objects

Looping Through a Collection of Objects. There are two ways of enumerating over objects. One may be considered easier than the other. Nevertheless the two ways are shown below. 1. Using a WHILE loop and GetEnumerator. 2. Using a foreach loop. … Continue reading

Posted in powershell | Tagged , | Leave a comment

Creating CSV files for use with Excel

CSV files Working on a recent project, I was using PowerShell to manipulate a list of MS Word documents that I had to process. Reading other articles on the Internet, I realised how useful it would be if I could … Continue reading

Posted in powershell | Tagged , | Leave a comment

.NET List Class

The .NET List Class represents a strongly typed list of objects. It also provides methods to search, sort, and manipulate lists. The following code gives an example on how the List Class can be used. Lines 41-46 produced a sorted output … Continue reading

Posted in powershell | Tagged , | Leave a comment

PowerShell enumerated types

The following code shows how to create your own enumerated types and a possible way of using the type. For the example above, the following code can be used to look at the definitions for the enumerated type. foreach ($m … Continue reading

Posted in powershell | Tagged , | Leave a comment

Parameter Attribute Declaration

The (PowerShell) Parameter attribute identifies a public property of the cmdlet class as a cmdlet parameter. This article is a useful reference to the keywords that can be used in a Param block of a function or script. For example: … Continue reading

Posted in powershell | Tagged , | Leave a comment

Reading/writing files

Overview I can’t remember why now, but recently I had reason to do some file input/output using PowerShell. I guess there are different ways of achieving this, but chose to practice using .NET from PowerShell.  The following code simply reads … Continue reading

Posted in powershell | Tagged , | 1 Comment