From 6be02aacc8989920bf895944d1b9e69a3a278000 Mon Sep 17 00:00:00 2001 From: David Brook Date: Wed, 22 Mar 2023 13:47:41 +0000 Subject: [PATCH] Fixing an issue in Push-EnrollUpdateableAsset --- CHANGELOG.md | 3 +++ source/Public/Push-EnrollUpdatableAsset.ps1 | 23 +++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b059bbc..c8b70ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fixed a coding issue in the Push-EnrollUpdatableAsset function + ## [1.0.17] - 2023-03-22 ## Fixed - Fixed an issue with the Add-DeploymentAudienceMember function where it was not processing the input correctly. diff --git a/source/Public/Push-EnrollUpdatableAsset.ps1 b/source/Public/Push-EnrollUpdatableAsset.ps1 index 48f732f..7d4e99c 100644 --- a/source/Public/Push-EnrollUpdatableAsset.ps1 +++ b/source/Public/Push-EnrollUpdatableAsset.ps1 @@ -20,7 +20,9 @@ function Push-EnrollUpdatableAsset { $azureDeviceIDs ) begin { + Write-Verbose "Starting function $($MyInvocation.MyCommand.Name)" # Create the param body base + Write-Verbose "Creating the param body base" $paramBody = @{ updateCategory = "driver" assets = @( @@ -29,25 +31,19 @@ function Push-EnrollUpdatableAsset { } process { if($PSCmdlet.ShouldProcess("Enroll Assets", "Enroll Assets")) { - $updateAudienceMembers = Get-DeploymentAudienceMember -policyID $updateAudienceID + Write-Verbose "Getting updatable assets" + $updatableAssets = Get-UpdatableAsset + Write-Verbose "Checking if the assets are already enrolled" foreach ($id in $azureDeviceIDs) { - IF (-Not($updateAudienceMembers.id -contains $id)) { + IF (-Not($updatableAssets | Where-Object { $_.id -match $id }).enrollments.updateCategory -notcontains "driver") { + Write-Verbose "Adding $id to the param body, as it is not already enrolled" $memberObject = @{ "@odata.type" = "#microsoft.graph.windowsUpdates.azureADDevice" id = $id } - $paramBody.addMembers += $memberObject + $paramBody.assets += $memberObject } - } - } - $updatableAssets = Get-UpdatableAsset - foreach ($id in $azureDeviceIDs) { - IF (-Not($updatableAssets | Where-Object { $_.id -match $id }).enrollments.updateCategory -notcontains "driver") { - $memberObject = @{ - "@odata.type" = "#microsoft.graph.windowsUpdates.azureADDevice" - id = $id - } - $paramBody.assets += $memberObject + Write-Verbose "Param Body has $($paramBody.assets.Count) assets" } } } @@ -58,5 +54,6 @@ function Push-EnrollUpdatableAsset { -Uri "https://graph.microsoft.com/beta/admin/windows/updates/updatableAssets/enrollAssets" ` -Body $paramBody } + Write-Verbose "Finished function $($MyInvocation.MyCommand.Name)" } } \ No newline at end of file