Author Posts

August 17, 2015 at 2:45 pm

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
}

August 17, 2015 at 2:56 pm

Same syntax.

RoomNumber = ($Get_ADComputer | Select -Expand RoomNumber)

If I'm following you correctly.

August 17, 2015 at 5:57 pm

Seems obvious now. 🙂

That gave the results I was looking for.

Thanks.