New-Object, ExpandProperty

This topic contains 2 replies, has 2 voices, and was last updated by  Grant Harrington 2 years, 4 months ago.

  • Author
    Posts
  • #28672

    Grant Harrington
    Participant

    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
    }

  • #28674

    Don Jones
    Keymaster

    Same syntax.

    RoomNumber = ($Get_ADComputer | Select -Expand RoomNumber)

    If I'm following you correctly.

  • #28683

    Grant Harrington
    Participant

    Seems obvious now. 🙂

    That gave the results I was looking for.

    Thanks.

You must be logged in to reply to this topic.