davesnb
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.mess age, $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 ..
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.mess
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 ?
IS this maybe one object is a string - one is a date etc ?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you make any progress on this or do you still need help with a resolution.
ASKER
Ok thanks for the clarification
e.g.
Open in new window
If this is an array you are creating you can simply assign using +=
Open in new window