2017-09-27 22 views
1

の場合:foreachのと、私は問題を持っている私のコードの後に​​リンクされ問題ここ

#Delivery Groups Information 
$dgroup = Invoke-RestMethod -Uri "https://${XMS}:4443/xenmobile/api/v1/deliverygroups/filter" -Body '{}' -Headers $headers -Method Post 

$new = 0 
$count = $dgroup.dglistdata.dglist.length 
for ($v=0; $v -lt $count; $v++) { 
    foreach ($dglistdata in $dgroup) { 
     Write-Host $dglistdata.dglistdata.dglist[$new].name 
     $new++ 
    } 
} 

$Host.UI.RawUI.ForegroundColor = "white" 
$dgroup = Read-Host -Prompt "Please provide Delivery Group Name for which notification will be sent" 
$message = Read-Host -Prompt "Please provide the message to be sent" 

#Devices 
$devices = Invoke-RestMethod -Uri "https://${XMS}:4443/xenmobile/api/v1/device/filter" -Body '{}' -Headers $headers -Method Post 

foreach ($device in $devices.filteredDevicesDataList) { 
    Write-Output $device.id >$null 
    Write-Output $device.platform >$null 
} 

foreach ($device in $devices.filteredDevicesDataList) { 
    $url = "https://${XMS}:4443/xenmobile/api/v1/device/" + $device.id + "/deliverygroups" 
    $global:dg = Invoke-RestMethod -Uri $url -Headers $headers -Method Get 
    foreach($deliverygroups in $dg) { 
     Write-Output $dg.deliveryGroups.name >$null 
    } 
} 

foreach ($device in $devices.filteredDevicesDataList) { 
    if ($dg.deliveryGroups.name -match $dgroup) { 
     Write-Host $device.devicemodel 
     Send-Notification 
    } else { 
     $dgroup = 0 
    } 
} 

情報:

がコードの主な目的は、デバイスがあり、どのグループに基づいてデバイスに通知を送信することですのメンバー。

例:

Result

が、私はそこに何かを逃してください: "DG 2" "DG 1"

結果の
iPhoneメンバーの

iPadのメンバー?実際に

+1

として...コードコードではなく、トリミングされたスクリーンショットを投稿してください。また、現在のスクリーンショットのサンプルは、あなたを助けるのに十分な情報ではありません。 '$ dgroup'とは何ですか? '$ dg'とは何ですか? '$ devices'はどのように定義されましたか? –

+0

コードの後: –

+0

もう一度、スクリーンショットではなく_code_を貼り付けてください。必要に応じてフォーマットをお手伝いします –

答えて

0

、私は解決策を見つけたと思う、私は他のループ内での通知のための私のループを含める必要として:

foreach($device in $devices.filteredDevicesDataList) 
{ 
$url = "https://${XMS}:4443/xenmobile/api/v1/device/" + $device.id + "/deliverygroups" 
$Global:dg=Invoke-RestMethod -Uri $url -Headers $headers -Method Get 
foreach($deliverygroups in $dg) 
{ 
write-output $dg.deliveryGroups.name >$Null 
If($dg.deliveryGroups.name -match $dgroup) 
{ 
write-host $device.devicemodel 
Send-notification 
} 
} 
} 
関連する問題