I have a powershell Script that retrieves logon data from Servers.
But I cannot get the output to display correctly.
This is the later part of the script that pipes data into two separate arrays and the Output should show the data separately but the output is merging the two arrays together.
This is the code:
###Get todays date
$Datestr = $Date.Date.ToString( "dd/MM/yyyy *")
##Display output
Write-Host "All Users logged on today..."
###pipe query into array1
$array1 = $Logonsfound | Select Username, LogonType, LastLogon | Where-Object LastLogon -Like $Datestr | Sort { $_.Lastlogon } -Descending
##Display array1
$array1
####A split should appear here
Write-Host "`n"
##Display output
Write-host "The Single User:"
###pipe query into array2
$$array2 = ($Logonsfound | Select Username, LogonType, LastLogon | Where-Object LastLogon -Like $Datestr | Sort { $_.Lastlogon } -Descending)[0]
##Display array2
$array2
The output is as follows:
All Users logged on today...
The Single User:
Username LogonType LastLogon
-------- --------- ---------
user1 Remote 21/02/2023 09:26:26
user2 Remote 21/02/2023 09:16:35
user1 Remote 21/02/2023 09:26:26
When I want the output to display like this:
All Users logged on today...
Username LogonType LastLogon
-------- --------- ---------
user1 Remote 21/02/2023 09:26:26
user2 Remote 21/02/2023 09:16:35
The Single User:
Username LogonType LastLogon
-------- --------- ---------
user1 Remote 21/02/2023 09:26:26
How do I split the output?
Thanks