Import-CSV and PSObject

Hello,

I have a problem to get below approach.

Imagine that I have csv file with content as below:

Head1;Head2;Head3;

xyz;---;---;

---;zyx;---;

---;---;xzy;

123;---;---;

---;213;---;

---;---;321;

I'd like to import this file to powershell (import-csv) and put whole content to PSObject that:

1. First line contains only headers - that if I put $PSObj[1] I'll get all headers

2. All three "letters lines" are joined to one PSObject item - that if I put "$PSObj[1]" I'll get all these 3 lines

3. All three "numbers lines" are joined to one PSObject item - that if I put "$PSObj[2]" I'll get all these 3 lines

I need points 2 and 3 because I need to compare imported information on subject level (Test1 or Test2) and not to compare information on each line level.

One facilitation (I hope) is that each PSObject item begines when in a row in first column is not "---" value. And end of this item is one row before a row where in first colum is different value than "---" (it is shown on above example)

Has anyone an idea how to do it?

 

February 17th, 2015 6:24am

Your explanation is impossible to understand.  Without examples ot tech lingo please just say what it is you need to do.

Example: "I want to compare apples and oranges."

By starting with a simple statement it will be easier to understand what you are trying to do.

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 6:47am

Hi jrv,

ok, I try to explain in other way...

I collect data by MyScript.ps1 and export it to csv file (to be readable in MS Excel). Layout of this output file looks like below:

Head1;Head2;Head3;

xyz;---;---;

---;zyx;---;

---;---;xzy;

123;---;---;

---;213;---;

---;---;321;


This means that when I open this file in excel I see this information like this

Head1    Head2    Head3
xyz            ---          ---
---             zyx         ---
---              ---         xzy
123            ---         ---
---             213        ---
---              ---         321

What I'd like to have is...

after import this csv content to powershell variable/object I'd like to have possibility to compare this (above) data with new collected by the same script but later. I want to regularly update the information in output file by run MyScript.ps1 compare collected information with existing output file.

The problem is that I need to compare group of rows

xyz;---;---;

---;zyx;---;

---;---;xzy;

instead of each row (xyz;---;---;).

I need to treat above three rows as a one - let say - "object", because (for example) second row (---;zyx;---;) may be the same for more than one "object". Therefore in my view "objects" consist of few rows of csv file (not only one).

In my case good think is that if in first column (header1) value is not "---", it is always unique so this would be a foothold. I can see two conditions:

1. for each row, if value of first column is not "---" this mean that this is first row of an "object"

next

2. for each row, if value of first column is not "---" this mean that this one row before is last row of an "object"

Then if I would have division into "objects" I'd like to compare it...

I hope you will get my point this time, I know that this is complicated.

February 17th, 2015 8:47am

You can use Compare-Object to compare to CSV files.

If you need other than consider writing a script and posting it if you have problems.

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 2:24pm

There's probably an easier way to do this, but:

$z = Import-Csv junk.csv -Delimiter ';'
$h = $z | gm -MemberType NoteProperty | Select-Object -ExpandProperty Name
for ($j = 0 ; $j -lt $z.Count; ) { $f = @{}; $h | % { $f[$_] = $z[$j++].$_ }; [PSCustomObject]$f }

This is v3 of PowerShell...



February 17th, 2015 6:02pm

There's probably an easier way to do this, but:

$z = Import-Csv junk.csv -Delimiter ';'
$h = $z | gm -MemberType NoteProperty | Select-Object -ExpandProperty Name
for ($j = 0 ; $j -lt $z.Count; ) { $f = @{}; $h | % { $f[$_] = $z[$j++].$_ }; [PSCustomObject]$f }

This is v3 of PowerShell...



Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 6:03pm

There's probably an easier way to do this, but:

$z = Import-Csv junk.csv -Delimiter ';'
$h = $z | gm -MemberType NoteProperty | Select-Object -ExpandProperty Name
for ($j = 0 ; $j -lt $z.Count; ) { $f = @{}; $h | % { $f[$_] = $z[$j++].$_ }; [PSCustomObject]$f }

This is v3 of PowerShell...



  • Edited by D'Thompson Tuesday, February 17, 2015 11:09 PM
February 18th, 2015 2:00am

There's probably an easier way to do this, but:

$z = Import-Csv junk.csv -Delimiter ';'
$h = $z | gm -MemberType NoteProperty | Select-Object -ExpandProperty Name
for ($j = 0 ; $j -lt $z.Count; ) { $f = @{}; $h | % { $f[$_] = $z[$j++].$_ }; [PSCustomObject]$f }

This is v3 of PowerShell...



  • Edited by D'Thompson Tuesday, February 17, 2015 11:09 PM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 2:00am

There's probably an easier way to do this, but:

$z = Import-Csv junk.csv -Delimiter ';'
$h = $z | gm -MemberType NoteProperty | Select-Object -ExpandProperty Name
for ($j = 0 ; $j -lt $z.Count; ) { $f = @{}; $h | % { $f[$_] = $z[$j++].$_ }; [PSCustomObject]$f }

This is v3 of PowerShell...



  • Edited by D'Thompson Tuesday, February 17, 2015 11:09 PM
February 18th, 2015 2:00am

Hi jrv, D'Thompson

@jrv I would use compare-object but my problem is that I need to have properly imported objects from csv file. below example shows that objects may consist not the same count of lines (below this is 5 or 9 lines).

Conditions which I think should be used:

  • Beginning of the objects are the rows where first column/position value is not like "head1" and "---" and "llllllllll".
  • Last rows of the objects contain in first column/position "llllllllll"

@D'Thompson I think you are going right way, could you try to write your code that I would have imported lines to objects as marked below? - object 1 (bold), object 2 (italic) having regard to headers

"Head1";"Head2";"Head3";"Head4";"Head5";"Head6";"Head7"
"TestName1";"---";"---";"---";"Generic";"1/8/2015 2:48:06 PM";""
"---";"---";"CommonDeploymentUtility";"6.4.0.4025";"---";"---";""
"---";"---";"CommonUtility";"6.4.0.4025";"---";"---";""
"---";"---";"Ionic";"1.9.1.5";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"
"TestName2";"---";"---";"---";"Generic";"6/17/2013 9:04:22 AM";""
"---";"Experiences.PublishingExperiences";"---";"---";"---";"---";""
"---";"---";"Experiences.ListDefinitions.ExperienceLists";"1.0.0.0";"---";"---";""
"---";"Material.News";"---";"---";"---";"---";""
"---";"---";"Material.News";"1.0.0.0";"---";"---";""
"---";"Material.PublishingMaterials";"---";"---";"---";"---";""
"---";"---";"Material";"1.0.0.0";"---";"---";""
"---";"Material.Search";"---";"---";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"



  • Edited by Przlwo 1 hour 52 minutes ago
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 4:30am

Hi jrv, D'Thompson

@jrv I would use compare-object but my problem is that I need to have properly imported objects from csv file. below example shows that objects may consist not the same count of lines (below this is 5 or 9 lines).

Conditions which I think should be used:

  • Beginning of the objects are the rows where first column/position value is not like "head1" and "---" and "llllllllll".
  • Last rows of the objects contain in first column/position "llllllllll"

@D'Thompson I think you are going right way, could you try to write your code that I would have imported lines to objects as marked below? - object 1 (bold), object 2 (italic) having regard to headers

"Head1";"Head2";"Head3";"Head4";"Head5";"Head6";"Head7"
"TestName1";"---";"---";"---";"Generic";"1/8/2015 2:48:06 PM";""
"---";"---";"CommonDeploymentUtility";"6.4.0.4025";"---";"---";""
"---";"---";"CommonUtility";"6.4.0.4025";"---";"---";""
"---";"---";"Ionic";"1.9.1.5";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"
"TestName2";"---";"---";"---";"Generic";"6/17/2013 9:04:22 AM";""
"---";"Experiences.PublishingExperiences";"---";"---";"---";"---";""
"---";"---";"Experiences.ListDefinitions.ExperienceLists";"1.0.0.0";"---";"---";""
"---";"Material.News";"---";"---";"---";"---";""
"---";"---";"Material.News";"1.0.0.0";"---";"---";""
"---";"Material.PublishingMaterials";"---";"---";"---";"---";""
"---";"---";"Material";"1.0.0.0";"---";"---";""
"---";"Material.Search";"---";"---";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"



  • Edited by Przlwo 1 hour 58 minutes ago
February 18th, 2015 4:31am

I think you need to sort out your terminology.  It is impossible to follow your statements.

Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 5:11am

Just converting your "CSV" into objects results in these 14 objects:

Head1 : TestName1
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonDeploymentUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

Head1 : TestName2
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 6/17/2013 9:04:22 AM
Head7 : 

Head1 : ---
Head2 : Experiences.PublishingExperiences
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Experiences.ListDefinitions.ExperienceLists
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.News
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material.News
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.PublishingMaterials
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.Search
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

If I understand you correctly, you want to combine the first 4 objects (0..3) into one object (the 5th object being a "divider") and objects 5..12 into a second object (the last object being a "divider")?

One issue I see right away is that objects (if you start counting from zero, as you would in an array) 1,2, and 3 are duplicating the values in properties Head3 and Head4. What do you do in this case? Use the last one so that you end up with this object:

Head1 : TestName1
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 
Do I understand you correctly?

February 18th, 2015 10:53am

Hi jrv, D'Thompson

@jrv I would use compare-object but my problem is that I need to have properly imported objects from csv file. below example shows that objects may consist not the same count of lines (below this is 5 or 9 lines).

Conditions which I think should be used:

  • Beginning of the objects are the rows where first column/position value is not like "head1" and "---" and "llllllllll".
  • Last rows of the objects contain in first column/position "llllllllll"

@D'Thompson I think you are going right way, could you try to write your code that I would have imported lines to objects as marked below? - object 1 (bold), object 2 (italic) having regard to headers

"Head1";"Head2";"Head3";"Head4";"Head5";"Head6";"Head7"
"TestName1";"---";"---";"---";"Generic";"1/8/2015 2:48:06 PM";""
"---";"---";"CommonDeploymentUtility";"6.4.0.4025";"---";"---";""
"---";"---";"CommonUtility";"6.4.0.4025";"---";"---";""
"---";"---";"Ionic";"1.9.1.5";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"
"TestName2";"---";"---";"---";"Generic";"6/17/2013 9:04:22 AM";""
"---";"Experiences.PublishingExperiences";"---";"---";"---";"---";""
"---";"---";"Experiences.ListDefinitions.ExperienceLists";"1.0.0.0";"---";"---";""
"---";"Material.News";"---";"---";"---";"---";""
"---";"---";"Material.News";"1.0.0.0";"---";"---";""
"---";"Material.PublishingMaterials";"---";"---";"---";"---";""
"---";"---";"Material";"1.0.0.0";"---";"---";""
"---";"Material.Search";"---";"---";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"



  • Edited by Przlwo Wednesday, February 18, 2015 9:31 AM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 12:28pm

Hi jrv, D'Thompson

@jrv I would use compare-object but my problem is that I need to have properly imported objects from csv file. below example shows that objects may consist not the same count of lines (below this is 5 or 9 lines).

Conditions which I think should be used:

  • Beginning of the objects are the rows where first column/position value is not like "head1" and "---" and "llllllllll".
  • Last rows of the objects contain in first column/position "llllllllll"

@D'Thompson I think you are going right way, could you try to write your code that I would have imported lines to objects as marked below? - object 1 (bold), object 2 (italic) having regard to headers

"Head1";"Head2";"Head3";"Head4";"Head5";"Head6";"Head7"
"TestName1";"---";"---";"---";"Generic";"1/8/2015 2:48:06 PM";""
"---";"---";"CommonDeploymentUtility";"6.4.0.4025";"---";"---";""
"---";"---";"CommonUtility";"6.4.0.4025";"---";"---";""
"---";"---";"Ionic";"1.9.1.5";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"
"TestName2";"---";"---";"---";"Generic";"6/17/2013 9:04:22 AM";""
"---";"Experiences.PublishingExperiences";"---";"---";"---";"---";""
"---";"---";"Experiences.ListDefinitions.ExperienceLists";"1.0.0.0";"---";"---";""
"---";"Material.News";"---";"---";"---";"---";""
"---";"---";"Material.News";"1.0.0.0";"---";"---";""
"---";"Material.PublishingMaterials";"---";"---";"---";"---";""
"---";"---";"Material";"1.0.0.0";"---";"---";""
"---";"Material.Search";"---";"---";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"



  • Edited by Przlwo Wednesday, February 18, 2015 9:31 AM
February 18th, 2015 12:28pm

Hi jrv, D'Thompson

@jrv I would use compare-object but my problem is that I need to have properly imported objects from csv file. below example shows that objects may consist not the same count of lines (below this is 5 or 9 lines).

Conditions which I think should be used:

  • Beginning of the objects are the rows where first column/position value is not like "head1" and "---" and "llllllllll".
  • Last rows of the objects contain in first column/position "llllllllll"

@D'Thompson I think you are going right way, could you try to write your code that I would have imported lines to objects as marked below? - object 1 (bold), object 2 (italic) having regard to headers

"Head1";"Head2";"Head3";"Head4";"Head5";"Head6";"Head7"
"TestName1";"---";"---";"---";"Generic";"1/8/2015 2:48:06 PM";""
"---";"---";"CommonDeploymentUtility";"6.4.0.4025";"---";"---";""
"---";"---";"CommonUtility";"6.4.0.4025";"---";"---";""
"---";"---";"Ionic";"1.9.1.5";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"
"TestName2";"---";"---";"---";"Generic";"6/17/2013 9:04:22 AM";""
"---";"Experiences.PublishingExperiences";"---";"---";"---";"---";""
"---";"---";"Experiences.ListDefinitions.ExperienceLists";"1.0.0.0";"---";"---";""
"---";"Material.News";"---";"---";"---";"---";""
"---";"---";"Material.News";"1.0.0.0";"---";"---";""
"---";"Material.PublishingMaterials";"---";"---";"---";"---";""
"---";"---";"Material";"1.0.0.0";"---";"---";""
"---";"Material.Search";"---";"---";"---";"---";""
"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll";"llllllllll"



  • Edited by Przlwo Wednesday, February 18, 2015 9:31 AM
Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 12:28pm

Hi D'Thompson,

Yes you are right, I think that to accomplish my idea I need to divide csv lines/items into separate objects as below:

Object 1 (5 items)

Head1 : TestName1
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonDeploymentUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

Object 2 (9 items)

Head1 : TestName2
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 6/17/2013 9:04:22 AM
Head7 : 

Head1 : ---
Head2 : Experiences.PublishingExperiences
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Experiences.ListDefinitions.ExperienceLists
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.News
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material.News
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.PublishingMaterials
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.Search
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

So all I need is code that import csv file and divide content to many objects according to below rules

  • Beginning (first item) of an object is csv item where first column/position (Head1) value is not like "---" and not like "llllllllll".
  • Last item of such object would be csv item where first column/position (Head1) value is "llllllllll"

The code should also be able to create many PSObjects (as variables) with unique names (e.g. $PSObj1, $PSObj2, PSObj3,...).


  • Edited by Przlwo 3 hours 17 minutes ago
February 19th, 2015 3:07am

Hi D'Thompson,

Yes you are right, I think that to accomplish my idea I need to divide csv lines/items into separate objects as below:

Object 1 (5 items)

Head1 : TestName1
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonDeploymentUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

Object 2 (9 items)

Head1 : TestName2
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 6/17/2013 9:04:22 AM
Head7 : 

Head1 : ---
Head2 : Experiences.PublishingExperiences
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Experiences.ListDefinitions.ExperienceLists
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.News
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material.News
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.PublishingMaterials
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.Search
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

So all I need is code that import csv file and divide content to many objects according to below rules

  • Beginning (first item) of an object is csv item where first column/position (Head1) value is not like "---" and not like "llllllllll".
  • Last item of such object would be csv item where first column/position (Head1) value is "llllllllll"

The code should also be able to create many PSObjects (as variables) with unique names (e.g. $PSObj1, $PSObj2, PSObj3,...).


  • Edited by Przlwo 3 hours 22 minutes ago
Free Windows Admin Tool Kit Click here and download it now
February 19th, 2015 3:08am

Hi D'Thompson,

Yes you are right, I think that to accomplish my idea I need to divide csv lines/items into separate objects as below:

Object 1 (5 items)

Head1 : TestName1
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonDeploymentUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

Object 2 (9 items)

Head1 : TestName2
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 6/17/2013 9:04:22 AM
Head7 : 

Head1 : ---
Head2 : Experiences.PublishingExperiences
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Experiences.ListDefinitions.ExperienceLists
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.News
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material.News
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.PublishingMaterials
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.Search
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

So all I need is code that import csv file and divide content to many objects according to below rules

  • Beginning (first item) of an object is csv item where first column/position (Head1) value is not like "---" and not like "llllllllll".
  • Last item of such object would be csv item where first column/position (Head1) value is "llllllllll"

The code should also be able to create many PSObjects (as variables) with unique names (e.g. $PSObj1, $PSObj2, PSObj3,...).


  • Edited by Przlwo Thursday, February 19, 2015 8:08 AM
February 19th, 2015 11:06am

Hi D'Thompson,

Yes you are right, I think that to accomplish my idea I need to divide csv lines/items into separate objects as below:

Object 1 (5 items)

Head1 : TestName1
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 1/8/2015 2:48:06 PM
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonDeploymentUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : CommonUtility
Head4 : 6.4.0.4025
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Ionic
Head4 : 1.9.1.5
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

Object 2 (9 items)

Head1 : TestName2
Head2 : ---
Head3 : ---
Head4 : ---
Head5 : Generic
Head6 : 6/17/2013 9:04:22 AM
Head7 : 

Head1 : ---
Head2 : Experiences.PublishingExperiences
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Experiences.ListDefinitions.ExperienceLists
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.News
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material.News
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.PublishingMaterials
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : ---
Head3 : Material
Head4 : 1.0.0.0
Head5 : ---
Head6 : ---
Head7 : 

Head1 : ---
Head2 : Material.Search
Head3 : ---
Head4 : ---
Head5 : ---
Head6 : ---
Head7 : 

Head1 : llllllllll
Head2 : llllllllll
Head3 : llllllllll
Head4 : llllllllll
Head5 : llllllllll
Head6 : llllllllll
Head7 : llllllllll

So all I need is code that import csv file and divide content to many objects according to below rules

  • Beginning (first item) of an object is csv item where first column/position (Head1) value is not like "---" and not like "llllllllll".
  • Last item of such object would be csv item where first column/position (Head1) value is "llllllllll"

The code should also be able to create many PSObjects (as variables) with unique names (e.g. $PSObj1, $PSObj2, PSObj3,...).


  • Edited by Przlwo Thursday, February 19, 2015 8:08 AM
Free Windows Admin Tool Kit Click here and download it now
February 19th, 2015 11:06am

First thing, forget generating variables like $PSObj1, $PSObj2, PSObj3, and use an array instead. You will find it difficult to write code to access your numbered variables without knowing how many there are.

February 19th, 2015 11:18pm

Hi Al Dunbar,

I can forget about variables like $PSObj1, $PSObj2, but...

For example $PSObj1 (above Object 1) represents information from a csv file (not actual information) and $PSObj2 (above Object 2) represents information live from system (actual information)

How can I compare these two objects by a hashtable? (remember that in real life there will be much more objects to compare that two)

If I could have variables ($PSObj1 = Object 1$PSObj2 =  Object 2) I could compare the objects like this:

If (($PSObj1[0]).Head1 -like ($PSObj2[0]).Head1) - If this is true I know that I have two the same objects to compare (because Head1 is always unique)

{

      and now I can move forward with next (optional) rules

      if ((($PSObj1[1]).Head2 -notlike ($PSObj2[1]).Head2)) -or (($PSObj1[1]).Head3 -notlike ($PSObj2[1]).Head3)) and so on and so on) - if true I know that something has been changed since csv file is created

}

Do you understand what I need to do?

How can I achieve this without objects inside variables?

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 6:43am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics