Hi all,

 

Thanks Michael, that does it, but since it's now moving into more of a
coding area, rather than using 'the power of Powershell', I'm running
into syntactic issues which are making things even more convoluted.
Firstly it assumes I've got a file full of data to process and the
for-loop going through the records needs an if statement/error trap
because one of my records only contains two elements, while others
contain three, so attempting to set the empty element upsets Powershell.
It's all getting a bit messy! 

 

I should say that the real (and tenuous) purpose of this exercise is to
compare two dates held within accounts on l...@edu, then write a record
based on the results. I hoped to do it in a nice few Powershell lines,
without having to write records to a local file/store... just do it
dynamically. But with 30k+ records, if we're going to store the records
locally, and get into loops, I might as well set a flag on that file to
show who has been processed and not re-process/get them from l...@edu. I
hope this makes sense. It appears to me that Powershell might be great
for setting Registry settings and other quick amendments, but writing
something a little more fiddly I might as well stick with vbscript to do
the processing and Powershell to do the read/writes. There isn't any
advantage to using Powershell.

 

Thanks!

 

Neal

 

FYI

$records = gc out.txt

echo $records

echo ' '  

foreach( $record in $records )

{

                $array = $record.Split(' ')

 

                $varVariable = $array[0].Trim()

                $varContent1 = $array[2].Trim()

                $varContent2 = $array[3].Trim()

 

                                ## process the data

                                echo "varVariable = $varVariable"

                                echo "varContent1 = $varContent1" 

                                echo "varContent2 = $varContent2"

}

 

Output :-

 

PS C:\MigrationWork> ./texttest.ps1

 

SamAccountName : XXCC11

WhenChanged : 08/09/2010 12:37:12

WhenCreated : 18/08/2009 11:10:18

 

You cannot call a method on a null-valued expression.

At C:\MigrationWork\texttest.ps1:12 char:46

+                 $varContent2 = $array[3].Trim <<<< ()

    + CategoryInfo          : InvalidOperation: (Trim:String) [],
RuntimeException

    + FullyQualifiedErrorId : InvokeMethodOnNull

 

varVariable = SamAccountName

varContent1 = XXCC11

varContent2 =

varVariable = WhenChanged

varContent1 = 08/09/2010

varContent2 = 12:37:12

varVariable = WhenCreated

varContent1 = 18/08/2009

varContent2 = 11:10:18

 

PS C:\MigrationWork>

 

From: Michael B. Smith [mailto:mich...@smithcons.com] 
Sent: 14 September 2010 13:08
To: NT System Admin Issues
Subject: RE: Really simple powershell query - text formatting...

 

There are a couple of ways to attack this. The easiest is probably to
continue to use the normal vbscript concepts of string handling.

 

$records = gc <filename.txt>

foreach( $record in $records )

{

                $array = $record.Split( ' ' )

                $varName = $array[0].ToUpper().Trim()

                $varData = $array[1].Trim()

                ## process the data

}

 

You can also do this with regular expressions and patterns. Not sure it
really buys you anything though.

 

Regards,

 

Michael B. Smith

Consultant and Exchange MVP

http://TheEssentialExchange.com

 

From: Palmer, Neal [mailto:npal...@uwic.ac.uk] 
Sent: Tuesday, September 14, 2010 7:47 AM
To: NT System Admin Issues
Subject: Really simple powershell query - text formatting...

 

Hi all,

 

I'm trying to do the most simple of things, so I can start writing in
Powershell instead of vbscript, but can't find a way to do it...
Basically I'm processing a large input stream (30k+ users from a remote
data source) of text, in two columns of Variable Name and Variable Data,
starting with a Unique ID, followed by 3 lines related to that ID, then
it repeats for the next user, e.g

 

ID            User1

FN          John

SN          Thomas

ID            User2

FN          Rick

SN          Rubin

.

Etc

 

What I want to do is group each variable per Unique ID and process them.
So I get something like

 

ID(1) = "User1"

FN(1) = "John"

SN(1) = "Thomas"

 

Simple, but as my columns don't have column headings, I can't find the
Powershell command to separate the Variable Name and Variable Data
string into variables I can use. This seems to be the universal example
of basic manipulation of columns, but the get-process command gives
column headers, which I don't have

 

$tring = get-process |select-object Name,VM -first 10

                "{0} is the second process, VM is {1}" -f
$tring[1].Name,$tring[1].VM

 

So I'm looking to isolate the Variables. I've tried using the
formatstring command, but I can't get it to return the entire variable,
only 1 character of text

 

$test = "ABCD EFGH"

$first = "{0}" -f $test[0]

echo $first

A

 

I need the whole word assign so, I'd like to do 

 

$test = "ABCD EFGH"

$first = "{0}" -f $test[<first word>] 

$second = ""{0}" -f $test[<second word>]

echo $first

John

echo $second

Thomas

 

Also these variables are of variable length, so 

 

$first = "{0}" -f $test[1-4] 

 

Wouldn't work. Help!?!

 

Many thanks,

 

Neal

 

P.S. My goal is to write something that will process the entire dataset
in Powershell. I can write the lot to a text file and do whatever I like
in vbscript, that's easy for me, but I'm trying to use Powershell in a
more intelligent way so that I don't have to store and process the data
locally. It may be that this 'online' method is too slow anyway, but I
want to try...

 

___________________________________________________________

 

Neal Palmer                                

Senior Technical Support Officer

 

Systems and Communications Services
Information Services Division
UWIC, Cardiff, Wales, CF5 2YB

 

UWIC Mysite
<http://mysites.staff.uwic.ac.uk/Person.aspx?accountname=CAMPUS\cc0078> 

___________________________________________________________

 

P SAVE PAPER - Please do not print this e-mail unless absolutely
necessary

 

 

 

 

 

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin


~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

<<image001.gif>>

Reply via email to