2
2
20ivs2020-04-13 09:19:18
PowerShell
20ivs, 2020-04-13 09:19:18

How to highlight certain values ​​by date?

I welcome everyone!
There is a script that collects certain events from the server logs.

$servername = "111.domain.com"
$username = "DOMAIN\user"
 
[xml]$equery = @"
<QueryList>
    <Query Id="0" Path="Microsoft-Windows-TerminalServices-Gateway/Operational">
    <Select Path="Microsoft-Windows-TerminalServices-Gateway/Operational">*[System[(EventID=303)]] and *[UserData[EventInfo[(Username='$username')]]]</Select>
    </Query>
</QueryList>
"@
Get-WinEvent -ComputerName $servername -FilterXML $equery |
   Select-Object TimeCreated, @{Name="SessionDuration";Expression={$_.Properties[6].Value}},
                              @{Name="User";Expression={$_.Properties[0].Value}},
                              @{Name="Source Network Address";Expression={$_.Properties[1].Value}},
                              @{Name="Resource";Expression={$_.Properties[3].Value}},MachineName | Out-GridView

Question for PowerShell experts - how to sort the output by date and add the SessionDuration values ​​for the selected date?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2020-04-13
@20ivs

1. ... | Sort-Object -Property TimeCreated
2.

$date = [datetime]'2020-04-13';

... |
   Where-Object { $_.TimeCreated.Date -eq $date } |
   Measure-Object -Sum -Property SessionDuration

Well, further to taste

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question