Powershell Foreach loop to return ID data

98 views Asked by At

I am currently trying to create a foreach loop to take each value from a list and search for it in return data from an API. For some reason I am getting NULL data when I try to loop it.

$agentList = (Import-CSV -Path 'O:\Test\AgentList.txt')

$Params = @{
    "Uri"     = "https://10.245.55.88:8834/agents"
    "Method"  = "GET"
    "Headers" = @{
        "X-ApiKeys" = "accessKey=$($AccessKey); secretKey=$($SecretKey)"
    }
}

$agentsNotInSC = Invoke-Restmethod @Params

$agentID = foreach ($agent in $agentList) {
    $agentID = $agentsNotInSC.agents | Where-Object { $_.name -eq $agent }
    $agentID.id
}

$agentID | Export-Csv -Path "O:\Test\IDAgent.CSV" -NoTypeInformation

trying to get all the return data and export it to a CSV

0

There are 0 answers