Here is the XML. I am looking for the siteid.
<result created="2018-10-13T13:11:18-05:00" host="redacted" status="OK">
<items>
<site>
<siteid>399700</siteid>
<name>
<![CDATA[ Warehouse ]]>
</name>
<connection_ok>1</connection_ok>
</site>
<site>
<siteid>547401</siteid>
<name>
<![CDATA[ Monterey Park ]]>
</name>
<connection_ok>1</connection_ok>
</site>
</items>
</result>
To obtain the data I am looking for, I first need to iterate through the XML for a client id, and then I can use the client id to find the site id for each client. Some clients have multiple sites.
While the clients are obtained correctly the sites are, for the lack of a better term, compressed.
Results:
ClientID: 12345 SiteID: 9876543210
The Site ID should be two individual numbers: 98765 43210
Here are the two functions I am working with:
$ClientsIDs = @()
$SiteIDs = @()
function Get-Clients() {
$clientdata = Invoke-RestMethod -Uri ($baseurl + $lc)
$clientid = $clientdata.result.items.client.clientid
$Script:ClientsIDs += $clientid
Write-Output("Client ID: " + $ClientsIDs)
}
function Get-Sites() {
foreach ($id in $Global:ClientsIDs) {
$sitedata = Invoke-RestMethod -Uri ($baseurl + $ls + $id)
$siteid = $sitedata.result.items.site.siteid
$SiteIDs += $siteid
}
Write-Output("Site ID: " + $SiteIDs)
}
Get-Clients
Get-Sites
(Only the URLs are not shown. The Write-Output
s are only for my benefit to make sure the data is being collected correctly. They will eventually be removed.)
How can I get the $sitedid
to properly be saved in the array?