New-Object, ExpandProperty

Welcome Forums General PowerShell Q&A New-Object, ExpandProperty

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 4 months ago.

  • Author
    Posts
  • #28672

    Participant
    Points: 1
    Rank: Member

    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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Same syntax.

    RoomNumber = ($Get_ADComputer | Select -Expand RoomNumber)

    If I'm following you correctly.

  • #28683

    Participant
    Points: 1
    Rank: Member

    Seems obvious now. 🙂

    That gave the results I was looking for.

    Thanks.

The topic ‘New-Object, ExpandProperty’ is closed to new replies.