I'm dealing with a PowerShell audit log, which I have imported from an XML dump.
Each row is a PowerShell event, including various fields such as:
Attribute:Cmdlet
(the name of the command that was executed)Attribute:Caller
(the username of the administrator who executed the command)CmdletParameters.Parameter
(input parameters that were provided for the command)
As you can see from the screenshot, CmdletParameters.Parameter
is a table column.
This is the column I am trying to expand.
Each PowerShell event can have an unlimited number of parameters.
(The maximum among this dataset is 17 parameters for a single event.)
For example, here's a command with two parameters:
Set-Mailbox -Identity Username1 -AccountDisabled FALSE
In this example, within the CmdletParameters.Parameter
table column, there would be two rows:
I would like to create two custom columns called ParameterNames
and ParameterValues
In this example, these custom columns would contain the text:
EDIT:
A commenter requested an example of the originating XML data.
I've included two event rows, with private information redacted.
<?xml version="1.0" encoding="utf-16"?>
<SearchResults>
<Event Caller="AdminUser1" Cmdlet="New-AdminAuditLogSearch" RunDate="2019-04-04T21:49:52+00:00" Succeeded="true" ObjectModified="ObjectUUID1" ExternalAccess="false" OriginatingServer="ServerName1 (IPAddress1)" ClientIP="[IPAddress2]:Port2">
<CmdletParameters>
<Parameter Name="StartDate" Value="4/3/2019 12:00:00 AM" />
<Parameter Name="EndDate" Value="4/4/2019 12:00:00 AM" />
<Parameter Name="ExternalAccess" Value="True" />
<Parameter Name="StatusMailRecipients" Value="AdminUser1" />
<Parameter Name="Name" Value="External admin audit log" />
</CmdletParameters>
</Event>
<Event Caller="AdminUser2" Cmdlet="New-AdminAuditLogSearch" RunDate="2019-04-04T21:33:08+00:00" Succeeded="true" ObjectModified="ObjectUUID2" ExternalAccess="false" OriginatingServer="ServerName2 (IPAddress3)" SessionId="ObjectUUID3" ClientIP="[IPAddress4]:Port4">
<CmdletParameters>
<Parameter Name="StartDate" Value="4/3/2019 12:00:00 AM" />
<Parameter Name="EndDate" Value="4/4/2019 12:00:00 AM" />
<Parameter Name="StatusMailRecipients" Value="AdminUser2" />
</CmdletParameters>
</Event>
</SearchResults>
EXTRA BONUS:
As I mentioned above, there are a maximum of 17 parameters per row in this dataset.
If I were to also create 17 columns for ParameterName1..ParameterName17
, how could I populate these columns?
Is it easier to convert the table column to a single text column first, and then parse that text into separate columns?