I have an array $data :
PS> $data
Datum User Computer
----- --------- --------
10/06/2013 13:10:56 [email protected] DC1$
10/06/2013 13:09:25 [email protected] DC2$
10/06/2013 10:05:13 [email protected] DC2$
7/06/2013 16:32:47 [email protected] DC1$
I want to get the latest dates from the $data array for each computer like this:
PS> $result
Datum User Computer
----- --------- --------
10/06/2013 13:10:56 [email protected] DC1$
10/06/2013 13:09:25 [email protected] DC2$
I really couldn't get this result. Could you please help me on this?
The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several . NET and UNIX formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs.
What is @() in PowerShell Script? In PowerShell, the array subexpression operator “@()” is used to create an array. To do that, the array sub-expression operator takes the statements within the parentheses and produces the array of objects depending upon the statements specified in it.
To access items in a multidimensional array, separate the indexes using a comma ( , ) within a single set of brackets ( [] ). The output shows that $c is a 1-dimensional array containing the items from $a and $b in row-major order.
Create an Array of Strings Using the [String[]] Method in PowerShell. To work with an array of strings in PowerShell, firstly, we have to create them. By using the “[String[]]” method, we will create a “$var” array of strings. This “$var” array of strings will contain the values: “PowerShell”, “String”, and “Array”.
$data | Foreach-Object {$_.Datum = [DateTime]$_.Datum; $_} |
Group-Object Computer |
Foreach-Object {$_.Group | Sort-Object Datum | Select-Object -Last 1}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With