Need help accessing hash table returned by recordset

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Don Smith Don Smith 2 years, 3 months ago.

  • Author
    Posts
  • #18406
    Profile photo of Don Smith
    Don Smith
    Participant

    Hello All,

    I need some help.
    I am running an AD search and I receive the output of the recordset in a variable.
    When I print out the variable it shows that the variable contains an unnamed hash table.
    I have tried everything I can think of to access the value in the hash table to make a comparison to.

    Ultimate goal. verify the system in the variable $strTargetHost is found in AD.

    code snippet – psudo code

    inside a for loop containing the names of the host systems I want to search for

    # retrieve the results of the Search
    $searchResult = $objRecordSet.fields.item("name") | Select-Object Name,Value

    Write-Host "DEBUG: searchResult = " $searchResult

    if ($objRecordSet.fields.item("name") -match $strTargetHost) { #latest iteration of attempts to access the Value data returned in the hash table array

    write out the data to a file
    }

    When I print out the contents of $searchResult = @{Name=name, Value=99W7XLN1}

    Question: How can I access the array that is being stored in $searchResult?
    How can I compare the Value ( in this case "99W7XLN1" to desired host ($strTargetHost) which is the same value 99W7XLN1

    Any assistance you could provide would be greatly appreciated.
    Thanks,

  • #18407
    Profile photo of Don Smith
    Don Smith
    Participant

    Never mind fellas, I finally figured it out after hours of trial and error.

    if (( $searchResult.value) -contains $strTargetHost) {

    # do it now

    }

You must be logged in to reply to this topic.