PowerShell Choose Strangeness

I have two select statements. "Headers" from the first (message, username generated by time) are used for the second (username generated by time).

Please look at the echo statement to see that tables \ outputs are combined into one.

Can someone explain why?

This needs to be run in the ps1 script to see the weirdness:

$before = get-date
$after = (get-date).AddDays(-1)

$a = Get-EventLog System -Before $before -After $after | ? {$_.Message -like "*start*"}

$a | select message, username,timegenerated

echo "----going through security----" 

$b = Get-Eventlog security -Before $before -After $after |?{$_.category -match "Logon/Logoff" } 

$b | select username,timegenerated

Conclusion:

Message                                                UserName                                               TimeGenerated
-------                                                --------                                               -------------
The Engine service was successfully sent a star...     NT AUTHORITY\SYSTEM                                    22/09/2011 09:32:09
The Engine service was successfully sent a star...     NT AUTHORITY\SYSTEM                                    21/09/2011 16:03:57
The Licensing Service service was successfu...         DOMAIN\username                                        21/09/2011 15:58:12
----going through security----
                                                       DOMAIN\9876ABC$                                        22/09/2011 14:05:41
                                                       DOMAIN\9876ABC$                                        22/09/2011 14:04:58
                                                       DOMAIN\9876ABC$                                        22/09/2011 14:03:40
                                                       DOMAIN\9876ABC$                                        22/09/2011 14:02:57
                                                       NT AUTHORITY\LOCAL SERVICE                             22/09/2011 14:01:59
+5
source share
2 answers

Seems like a formatting issue, it seems to work as expected:

$before = get-date
$after = (get-date).AddDays(-1)

$a = Get-EventLog System -Before $before -After $after | ? {$_.Message -like "*start*"}

$a | select message, username,timegenerated | format-table -force

echo "----going through security----" 

$b = Get-Eventlog security -Before $before -After $after |?{$_.category -match "Logon/Logoff" } 

$b | select username,timegenerated | format-table -force

In addition, it definitely looks like an error regarding the output of several custom psobjects (created above as a result of the selection).

PSObject , (.. ):

$before = get-date
$after = (get-date).AddDays(-1)

$a = Get-EventLog System -Before $before -After $after | ? {$_.Message -like "*start*"}
$a = $a | `
    % {New-Object PSObject -Property `
        @{Message = $_.message; Username = $_.username; Timegenerated = $_.timegenerated}
    }
$a

echo "----going through security----" 

$b = Get-Eventlog security -Before $before -After $after |?{$_.category -match "Logon/Logoff" } 
$b = $b | `
    % {New-Object PSObject -Property `
        @{Username = $_.username; Timegenerated = $_.timegenerated}
    }
$b

PS_ISE :

$a | gm
$b | gm

, . , ; , :

$b = $b | `
    % {New-Object PSObject -Property `
        @{Username = $_.username; Timegenerated = $_.timegenerated}
    }

$b = $b | `
    % {New-Object PSObject -Property `
        @{UsernameB = $_.username; TimegeneratedB = $_.timegenerated}
    }

, , , . Get-Member , .

, Microsoft Connect, , PSCustomObjects v3, . .

+2

PowerShell. , . .

$a $b , , . .

+1

All Articles