New-Object, ExpandProperty

When running the following and I have data in the PC’s roomNumber ADUC attribute, it’s results are presented as {Room 101}. I know when used in a select statement, I can use -ExpandProperty to make the result Room 101.

Get-ADComputer -filter * -Properties * | select -ExpandProperty roomNumber

When I’m building a New-Object, what syntax would I use to expand property for:
RoomNumber = $Get_ADComputer.RoomNumber

$Get_ADComputerAll = Get-ADComputer -filter * -Properties * | select * -First 1
foreach ($Get_ADComputer in $Get_ADComputerAll) {

$Get_ADComputerProps = [ordered]@{
	CanonicalName = $Get_ADComputer.CanonicalName
	CN = $Get_ADComputer.CN
	whenChanged = $Get_ADComputer.whenChanged
	whenCreated = $Get_ADComputer.whenCreated
    RoomNumber = $Get_ADComputer.RoomNumber
} #end Get_ADComputerProps

$Get_ADComputerObj = New-Object -TypeName PSObject -Property $Get_ADComputerProps
Write-Output $Get_ADComputerObj


Same syntax.

RoomNumber = ($Get_ADComputer | Select -Expand RoomNumber)

If I’m following you correctly.

Seems obvious now. :slight_smile:

That gave the results I was looking for.