Kirneh
Kirneh

Reputation: 3

Creating a $variable from a specific part of a txt file

I'm trying to get PowerShell to use a specific section of a text file as a $variable to be used later in the script.

With Get-Content and index I can get to the point of having a whole line, but I just want one word to be the variable, not the whole thing.

The alphanumeric code will always be in the same location exactly line 5 (counting the first one as 0 of course) and the position in would be between the characters 22 to 30 (or the last 8 characters of that line).

I would like that section of the document to be identified as $txtdoc, to be used later in:

$inputfield = $ie.Document.getElementByID('input5')

$inputfield.value = $txtdoc

The txt file contains the following

From:   *************
Sent:   *************
To: *******************
Subject:    *************

On-Demand Tokencode: 79960739
Expires after use or 60 minutes

Upvotes: 0

Views: 140

Answers (1)

CB.
CB.

Reputation: 60918

this maybe?

$variable = ( gc mytext.txt )[5].substring(21,8)

Upvotes: 2

Related Questions