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
Actual behavior
Error details
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
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
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.
The result is a list of ServicePrincipalName. There is no corresponding SamAccountName. The content of the
$aavariable 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 aboveError details
No obvious errors.Environment data
Visuals
No response