Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not an issue! #17

Closed
TWKDreamState opened this issue Mar 13, 2024 · 2 comments
Closed

Not an issue! #17

TWKDreamState opened this issue Mar 13, 2024 · 2 comments

Comments

@TWKDreamState
Copy link

Hi,

I work in education so might be a bit different in my needs but I made a couple of adjustments that I thought I would share, but I don't know how to do pull requests, etc.

We needed to add to multiple groups (dependent on being a staff device or pupil device) - nothing major and might not affect businesses in the same way.

I altered the following:

[Parameter(Mandatory = $False, ParameterSetName = 'Online')] [String[]] $AddToGroup = "", #(to accept an array)

and:

    # Add the device to the specified AAD group
    if ($AddToGroup) {
		foreach ($ADGroup in $AddToGroup){
			$aadGroup = Get-MgGroup -Filter "DisplayName eq '$ADGroup'"
			if ($aadGroup) {
				$autopilotDevices | ForEach-Object {
					$uri = "https://graph.microsoft.com/beta/devices?`$filter=deviceId eq '" + $_.azureActiveDirectoryDeviceId + "'"
					$aadDevice = (Invoke-MgGraphRequest -Uri $uri -Method GET -OutputType PSObject -SkipHttpErrorCheck).value
					if ($aadDevice) {
						Write-Host "Adding device $($aadDevice.displayName) to group $ADGroup"
						New-MgGroupMember -GroupId $aadGroup.Id -DirectoryObjectId $aadDevice.id
					}
					else {
						Write-Error "Unable to find Azure AD device with ID $($aadDevice.deviceId)"
					}
				}
				Write-Host "Added devices to group '$ADGroup' ($($aadGroup.Id))"
			}
			else {
				Write-Error "Unable to find group $ADGroup"
			}
		}
    } #to deal with the array

Just might be useful for someone else hopefully! Please delete or move as not an issue!

@andrew-s-taylor
Copy link
Owner

Thank you, have added it, will upload once I have signed it

@andrew-s-taylor
Copy link
Owner

All uploaded now both here and on PSGallery. Let me know if you have any issues with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants