Skip to content

Select-object with AD object appears to be buggy #21028

@Tarjei-stavanger

Description

@Tarjei-stavanger

Prerequisites

Steps to reproduce

I'm trying to produce a list pair of SamAccountName and ServicePrincipalName as a CSV file. I have tried the code on all PowerShell implementations I have available : ISE, Ordinary Powershell, Powershell 7.4.

The original code I use is as follows

$FormatEnumerationLimit = -1;
$aa = Get-ADComputer -Filter { ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName
   $aa | select-object -Property SamAccountName -ExpandProperty ServicePrincipalName |
     export-CSV -NoTypeInformation -delimiter ';' C:\Temp\server_spn.csv;

What I get as a result is a list of hostnames and the length of the ServicePrincipalName. This is a bit surprising.

When I tried to locate the problem I use the following code.

$aa = Get-ADComputer -Filter { ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName
   $aa | select-object -Property SamAccountName -ExpandProperty ServicePrincipalName

The result is a list of ServicePrincipalName. There is no corresponding SamAccountName. The content of the $aa variable is as expected.

The results that I'm getting from the code is rather surprising and to me, totally unexpected.

Expected behavior

See above.

Actual behavior

See also above

Error details

No obvious errors.

Environment data

Windows 10 Enterprise

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions