Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Compare two variables with multiple objects

$
0
0

I am trying to do the following, not sure something is missing or a syntax error, i am not able to figure out. if someone can assist would be great help.

Here is what i would like to achieve, fetch list of devices from Intune with selective objects and the same way fetching asset management device list with again some selective objects to validate the existence. 

So its like this,  source be (Intune) and destination as (SomeAssetMgmApp), the returned data is then collected in the following variables "$AllDevices" & "$AssetModelLists" and finally do a if condition to do some action based on the condition.

$AllDevices = (Invoke-RestMethod -Uri $url -Headers $authHeader -Method Get).value | Where-Object {$_.manufacturer -eq "Apple"} | select-object userDisplayName,deviceName,enrolledDateTime,lastSyncDateTime,serialNumber,imei,model,totalStorageSpaceInBytes,isSupervised

$AssetModelLists = (Invoke-RestMethod -Uri $uri -Headers $assetauthHeader -Method Get).rows | where-object {$_.manufacturer.name -eq "Apple"}

foreach($AllDevice in ($AllDevices | select-object serialnumber))
        {
        foreach($AssetModelList in ($AssetModelLists | select-object serialnumber))
{

if($AllDevice.serialnumber -notcontains $AssetModelList.serialnumber){
do something
}
else{do else}
}
}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>