Skip to content

Commit

Permalink
Updated DeploymentAudienceMember Cmdlets
Browse files Browse the repository at this point in the history
  • Loading branch information
David Brook committed Mar 22, 2023
1 parent c484341 commit 2617b93
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added
- Functionality to Add-DeploymentAudienceMember to allow for using either the policyID or AudienceID
- Functionality to Get-DeploymentAudienceMember to allow for using either the policyID or AudienceID

## Fixed
- Renamed Push-EnrollUpdateableAsset to Push-EnrollUpdatableAsset to resolve a spelling error

Expand Down
27 changes: 21 additions & 6 deletions source/Public/Add-DeploymentAudienceMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,46 @@ function Add-DeploymentAudienceMember {
.DESCRIPTION
This function will check if the deployments audiences have the devices as members, and if not they will be added to the audience.
.EXAMPLE
Add-DeploymentAudienceMember -azureDeviceIDs ("ID1","ID2") -updateAudienceID <AudienceID>
Add-DeploymentAudienceMember -azureDeviceIDs ("ID1","ID2") -audienceID <AudienceID>
.PARAMETER azureDeviceIDs
The Azure Device IDs to add to the audience.
.PARAMETER updateAudienceID
.PARAMETER audienceID
The Update Audience ID to add the members to.
.PARAMETER policyID
The Update Policy ID to add the members to.
.NOTES
You can specify either the audienceID or policyID parameter, if both are specified the audienceID will be used.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[array]
$azureDeviceIDs,
# The Update Audience ID
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $false)]
[string]
$audienceID,
[Parameter(Mandatory = $false)]
[string]
$updateAudienceID
$policyID
)
begin {
if ([String]::IsNullOrEmpty($audienceID) -and ([String]::IsNullOrEmpty($policyID))) {
throw "You must specify either the audienceID or policyID parameter."
}
# Create the param body base
$paramBody = @{
addMembers = @(
)
}
}
process {
$updateAudienceMembers = Get-DeploymentAudienceMember -policyID $updateAudienceID
IF (-Not([String]::IsNullOrEmpty($audienceID))) {
$updateAudienceMembers = Get-DeploymentAudienceMember -audienceID $audienceID
}
elseif (([String]::IsNullOrEmpty($policyID))) {
$updateAudienceMembers = Get-DeploymentAudienceMember -policyID $policyID
}
foreach ($id in $azureDeviceIDs) {
IF (-Not($updateAudienceMembers.id -contains $id)) {
$memberObject = @{
Expand All @@ -44,7 +59,7 @@ function Add-DeploymentAudienceMember {
IF ($paramBody.addMembers.Count -ge 1) {
Invoke-MgGraphRequest `
-Method POST `
-Uri "https://graph.microsoft.com/beta/admin/windows/updates/deploymentAudiences('$updateAudienceID')/updateAudience" `
-Uri "https://graph.microsoft.com/beta/admin/windows/updates/deploymentAudiences('$audienceID')/updateAudience" `
-Body $paramBody
}
}
Expand Down
25 changes: 21 additions & 4 deletions source/Public/Get-DeploymentAudienceMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,34 @@ function Get-DeploymentAudienceMember {
Get-DeploymentAudienceMember -policyID <PolicyID>
.PARAMETER policyID
The policy ID to get the members for.
.PARAMETER audienceID
The audience ID to get the members for.
.NOTES
You can specify either the audienceID or policyID parameter, if both are specified the audienceID will be used.
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $false)]
[string]
$policyID,
[Parameter(Mandatory = $false)]
[string]
$policyID
$audienceID
)
begin {
if ([String]::IsNullOrEmpty($audienceID) -and ([String]::IsNullOrEmpty($policyID))) {
throw "You must specify either the audienceID or policyID parameter."
}
}
process {
try {
$policy = Get-DriverUpdatePolicy -policyID $policyID
$members = Invoke-GetRequest -Uri "https://graph.microsoft.com/beta/admin/windows/updates/deploymentAudiences('$($policy.audience.id)')/members" -All
if(-Not([String]::IsNullOrEmpty($audienceID))) {
$members = Invoke-GetRequest -Uri "https://graph.microsoft.com/beta/admin/windows/updates/deploymentAudiences('$($audienceID)')/members" -All
}
ELSEIF (-Not([String]::IsNullOrEmpty($policyID))) {
$policy = Get-DriverUpdatePolicy -policyID $policyID
$members = Invoke-GetRequest -Uri "https://graph.microsoft.com/beta/admin/windows/updates/deploymentAudiences('$($policy.audience.id)')/members" -All
}
}
catch {
throw "Unable to get the members of the deployment audience. $($_.Exception.Message)"
Expand Down

0 comments on commit 2617b93

Please sign in to comment.