List view issue

Welcome Forums General PowerShell Q&A List view issue

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

 
Participant
4 years, 11 months ago.

  • Author
    Posts
  • #15260

    Participant
    Points: 0
    Rank: Member

    Hi, just having an issue displaying output in listview. Want to get dc server name in column 1 and site in column 2.

    Below shows all the data, but all in column one.

    function updatedclist
    {
    $Config = ([adsi]"LDAP://rootdse").ConfigurationNamingContext
    $dse = [adsi]"LDAP://$config"
    $searcher = New-Object DirectoryServices.DirectorySearcher ($dse, "ObjectClass=nTDSDSA")
    $searcher.findall() |
    ForEach-Object{
    $DCs = new-object System.Windows.Forms.ListViewItem([adsi]$_.path).parent
    $server = $DCs | foreach { ($_ -split 'CN=')[1] -replace ','}
    $item2.SubItems.Add($server)
    $site = $DCs | foreach { ($_ -split 'CN=')[3] -replace ','}
    $item2.SubItems.Add($site)
    $list2.Items.AddRange(($server,$site))
    }

    Thanks
    David

  • #15263

    Participant
    Points: 0
    Rank: Member

    I'd look at getting your data in a manageable format and then add it to the list.

    This will give you an output of DC and site

    Get-ADObject -SearchBase "CN=Configuration,$(Get-ADDomain | select -ExpandProperty DistinguishedName)" -LDAPFilter "(ObjectClass=nTDSDSA)" |
    select -ExpandProperty DistinguishedName |
    foreach {

    $data = $psitem -split ","

    $props = [ordered]@{
    DC = ($data[1] -split "=")[1]
    Site = ($data[3] -split "=")[1]
    }

    New-Object -TypeName PSObject -Property $props

    }

    You can loop through the objects and add to the List

    In your code I'm not sure what this line is doing
    $DCs = new-object System.Windows.Forms.ListViewItem([adsi]$_.path).parent

    but I think its where your problem lies

The topic ‘List view issue’ is closed to new replies.

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