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

3 years, 9 months ago.

  • Author
  • #28672

    Topics: 16
    Replies: 22
    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Same syntax.

    RoomNumber = ($Get_ADComputer | Select -Expand RoomNumber)

    If I'm following you correctly.

  • #28683

    Topics: 16
    Replies: 22
    Points: 1
    Rank: Member

    Seems obvious now. 🙂

    That gave the results I was looking for.


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

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort