Tag Archives: powershell

Text file with line numbers

For some time now I’ve wanted to create text files with line numbers. An example of this could be: This can be useful if I want to use the line numbers to refer to. For example, having a text file … Continue reading

Posted in powershell | Tagged | Leave a comment

Function template

The following code can be used as a function template. I’ve found that using  BEGIN, PROCESS and END blocks makes the function more structured and my life a lot easier.  

Posted in powershell | Tagged | Leave a comment

Using $PSBoundParameters

$PSBoundParameters is one example of a PowerShell automatic variable. As the documentation tells us: … variables that store state information for PowerShell. These variables are created and maintained by PowerShell. Some basic examples of using this variable are as follows: … Continue reading

Posted in powershell | Tagged | Leave a comment

Create numbered test files

I often have the need to create numbered test files such as for example: myfile.txt.001 myfile.txt.002 : myfile.txt.099 or whatever the maximum numbered test file is. It doesn’t have to be 99 of course. In this example, I’m going to … Continue reading

Posted in powershell | Tagged | Leave a comment

Centre PowerShell forms

The .NET Framework class Form represents a window or dialog box that makes up an application’s user interface. In other words this is how we can build a GUI interface to an application with forms and dialog boxes.   The StartPosition property of … Continue reading

Posted in powershell | Tagged | Leave a comment

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