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 ..
Powershell

Avatar of undefined
Last Comment
davesnb
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
davesnb
Flag of Canada image

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?
Avatar of becraig
becraig
Flag of United States of America image

What are the challenges  ?

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

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of becraig
becraig
Flag of United States of America image

Did you make any progress on this or do you still need help with a resolution.
Avatar of davesnb
davesnb
Flag of Canada image

ASKER

Ok thanks for the clarification
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo