Link to home
Start Free TrialLog in
Avatar of davesnb
davesnbFlag for Canada

asked on

Powershell and combining different object arrays

Hello EE,

I wish to create a script whereby it does 3 core tasks

1-  $getapplicationevents = get-eventlog -logname application

2-   $getsystemevents = get-eventlog -logname system

3-  $errorlogs = import-csv "c:\logs\logs.csv"

At this point i wish to combine certain member properties of each of the previous objects into a new "master object" with the goal of inserting into a database table or export to csv. All of the 3 objects would have a similar property the "host's name" . This would be similar concept to a primary key

My question is around the combining of certain member properties ;

Using $masterobject as the target for combining, with $getapplicationevents.message, $getsystemevents.message and $errorlogs.message in one array of objects ,$masterobject .The understanding is i would need to create the $masterobject and then use the add-member command but unsure of the structure from here ..
Avatar of becraig
becraig
Flag of United States of America image

If these are all strings you can simply just combine them if that is what you are after.

e.g.

 $masterobject =  "$getapplicationevents.message" + "$getsystemevents.message " + " $errorlogs.message " 

Open in new window


If this is an array you are creating you can simply assign using +=



 $masterobject +=  "$getapplicationevents.message" + "$getsystemevents.message " + " $errorlogs.message " 

Open in new window

Avatar of davesnb

ASKER

That works, however the objects are different type, so if I wish to export to csv or insert to database , the columns will not be consistent. It will assume the master object is of type ( last type combined) when using $masterobject | get-member and $masterobject will only show the members of the last type combined . So I ideally, I need a $master obejct that combines all the members of each object into one master. thoughts?
What are the challenges  ?

IS this maybe one object is a string - one is a date etc  ?
Avatar of davesnb

ASKER

Right , they are of different type . Two are of type diagnostic entry ( get-eventlog), one is a import-csv which is a different type
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you make any progress on this or do you still need help with a resolution.
Avatar of davesnb

ASKER

Ok thanks for the clarification