简体   繁体   中英

Converting a multivalued attribute serialnumber

I am looking to pull LastLogonDate, SerialNumber, Name and Description from AD. I have everything working except when I open the csv instead of the serialnumber is gives me: Microsoft.AdctiveDirectory.Management.ADPropertyValueCollection. From what I've looked up it is because it is a multivalued attribute. The code I currently have that I thought would fix this problem is:

 Get-ADDomainController -filter * | 
% { Get-ADComputer -Filter * -server $_.name -Properties Name,Description,serialNumber,LastLogonDate -SearchBase "DC=DELETED,DC=com" } | 
Select Name,Description,@{N='serialNumber'E={$_.serialNumber[0]}},LastLogonDate |
Export-Csv "C:\scripts\ComputerLastLogon.csv" -NoTypeInformation

However, now I am getting these errors: http://i.imgur.com/0BdC153.png

And if it helps at all, here is the code I was using when I first got the csv to show Microsoft.ActiveDirectory... :

Get-ADDomainController -filter * | 
% { Get-ADComputer -Filter * -server $_.name -Properties Name,Description,serialNumber,LastLogonDate -SearchBase "DC=DELETED,DC=com" } | 
Select Name,Description,SerialNumber,LastLogonDate |
Export-Csv "C:\scripts\ComputerLastLogon.csv" -NoTypeInformation

The answer might make you feel a bit silly but don't feel bad, you are missing a ; in your expression it should be

@{N='serialNumber';E={$_.serialNumber[0]}}

Try that and tell me if it works, it did for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM