Why is the output format changed when running two PowerShell commands in one line?

前端 未结 2 1119
挽巷
挽巷 2020-12-19 19:02

I\'m getting unexpected results when executing two PowerShell commands separated by a semicolon. The output of the second command changes. If I run them in reverse order, I

2条回答
  •  青春惊慌失措
    2020-12-19 19:18

    When the powershell console formatter sees objects of multiple types, it will default to outputting based on the first element output. For Date it output as a list, for the custom object output from Select-Object, it's a table. How the output is formatted depends on the type of the object itself (see help About Format.ps1xml). You can force the output of Select-Object to be a table using Format-Table:

    get-date; Get-ADPrincipalGroupMembership username | Select-Object name | Format-Table
    

提交回复
热议问题