Solved

Powershell and combining different object arrays

Posted on 2014-03-05
7
296 Views
Last Modified: 2014-04-02
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 ..
0
Comment
Question by:davesnb
  • 4
  • 3
7 Comments
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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

0
 

Author Comment

by:davesnb
Comment Utility
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?
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
What are the challenges  ?

IS this maybe one object is a string - one is a date etc  ?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:davesnb
Comment Utility
Right , they are of different type . Two are of type diagnostic entry ( get-eventlog), one is a import-csv which is a different type
0
 
LVL 28

Accepted Solution

by:
becraig earned 500 total points
Comment Utility
You cast the objects to the different types

Probably best to reassign the variables:
e.g.
$ermsg = [string]$errorlogs.message


More info on how to do this here:
http://mcpmag.com/articles/2013/07/23/object-spell-in-powershell.aspx
0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
Did you make any progress on this or do you still need help with a resolution.
0
 

Author Closing Comment

by:davesnb
Comment Utility
Ok thanks for the clarification
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now