Advertisement
Guest User

IntuneAAD-GroupScan.ps1

a guest
Jun 29th, 2022
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1.  
  2.  
  3. # Running the sample script on all AAD groups
  4.  
  5. # Connect and change schema
  6. Connect-MSGraph -ForceInteractive
  7. Update-MSGraphEnvironment -SchemaVersion beta
  8. Connect-MSGraph
  9.  
  10. $Groups = Get-AADGroup | Get-MSGraphAllPages
  11. $Groups = $Groups | sort-object displayname
  12.  
  13. $AllAssignedApps = Get-IntuneMobileApp -Expand assignments | Select id, displayName, lastModifiedDateTime, assignments
  14. $AllDeviceCompliance = Get-IntuneDeviceCompliancePolicy -Select id, displayName, lastModifiedDateTime, assignments -Expand assignments
  15. $AllDeviceConfig = Get-IntuneDeviceConfigurationPolicy -Select id, displayName, lastModifiedDateTime, assignments -Expand assignments
  16.  
  17. # Device Configuration Powershell Scripts
  18. $Resource = "deviceManagement/deviceManagementScripts"
  19. $graphApiVersion = "Beta"
  20. $uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)?`$expand=groupAssignments"
  21. $DMS = Invoke-MSGraphRequest -HttpMethod GET -Url $uri
  22. $AllDeviceConfigScripts = $DMS.value
  23.  
  24. # Administrative templates
  25. $Resource = "deviceManagement/groupPolicyConfigurations"
  26. $graphApiVersion = "Beta"
  27. $uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)?`$expand=Assignments"
  28. $ADMT = Invoke-MSGraphRequest -HttpMethod GET -Url $uri
  29. $AllADMT = $ADMT.value
  30.  
  31. # Settings Catalogs
  32. $Resource = "deviceManagement/configurationPolicies"
  33. $graphApiVersion = "Beta"
  34. $uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)?`$expand=Assignments"
  35. $SC = Invoke-MSGraphRequest -HttpMethod GET -Url $uri
  36. $AllSC = $SC.value
  37.  
  38.  
  39.  
  40. Write-host "Total number of Apps found: $($AllAssignedApps.DisplayName.Count)" -ForegroundColor cyan
  41. Write-host "Total number of Device Compliance policies found: $($AllDeviceCompliance.DisplayName.Count)" -ForegroundColor cyan
  42. Write-host "Total number of Device Configurations found: $($AllDeviceConfig.DisplayName.Count)" -ForegroundColor cyan
  43. Write-host "Total number of Device Configurations Powershell Scripts found: $($AllDeviceConfigScripts.DisplayName.Count)" -ForegroundColor cyan
  44. Write-host "Total number of Device Administrative Templates found: $($AllADMT.DisplayName.Count)" -ForegroundColor cyan
  45. Write-host ""
  46. Write-host ""
  47. Write-host ""
  48.  
  49.  
  50.  
  51.  
  52. #### Config
  53. Foreach ($Group in $Groups) {
  54. #Write-host "AAD Group Name: $($Group.displayName)" -ForegroundColor Green
  55.  
  56. # Apps
  57. #$AllAssignedApps = Get-IntuneMobileApp -Filter "isAssigned eq true" -Select id, displayName, lastModifiedDateTime, assignments -Expand assignments | Where-Object {$_.assignments -match $Group.id}
  58. #$AllAssignedApps = Get-IntuneMobileApp -Expand assignments | Select id, displayName, lastModifiedDateTime, assignments | Where-Object {$_.assignments -match $Group.id}
  59.  
  60. $AssignedApps = $AllAssignedApps | Where-Object {$_.assignments.id -match $Group.id}
  61. $DeviceCompliance = $AllDeviceCompliance | Where-Object {$_.assignments.id -match $Group.id}
  62. $DeviceConfig = $AllDeviceConfig | Where-Object {$_.assignments.id -match $Group.id}
  63. $DeviceConfigScripts = $AllDeviceConfigScripts | Where-Object {$_.groupAssignments.id -match $Group.id}
  64. $ADMT = $AllADMT | Where-Object {$_.assignments.id -match $Group.id}
  65. $SC = $AllSC | Where-Object {$_.assignments -match $Group.id}
  66.  
  67. if (($($AssignedApps.DisplayName.Count) -gt 0) -or ($($DeviceCompliance.DisplayName.Count) -gt 0) -or ($($DeviceConfig.DisplayName.Count) -gt 0) -or ($($DeviceConfigScripts.DisplayName.Count) -gt 0) -or ($($ADMT.DisplayName.Count) -gt 0) -or ($($SC.DisplayName.Count) -gt 0))
  68. {
  69. Write-host "AAD Group Name: $($Group.displayName)" -ForegroundColor Green
  70. }
  71. If ($($AssignedApps.DisplayName.Count) -gt 0)
  72. {
  73. Write-host "Number of Apps found: $($AssignedApps.DisplayName.Count)" -ForegroundColor magenta
  74. }
  75. #Write-host "Number of Apps found: $($AllAssignedApps.DisplayName.Count)" -ForegroundColor cyan
  76. Foreach ($Config in $AssignedApps) {
  77.  
  78. Write-host $Config.displayName -ForegroundColor Yellow
  79.  
  80. }
  81.  
  82.  
  83. # Device Compliance
  84. If ($($DeviceCompliance.DisplayName.Count) -gt 0)
  85. {
  86. Write-host "Number of Device Compliance policies found: $($DeviceCompliance.DisplayName.Count)" -ForegroundColor magenta
  87. }
  88. #$AllDeviceCompliance = Get-IntuneDeviceCompliancePolicy -Select id, displayName, lastModifiedDateTime, assignments -Expand assignments | Where-Object {$_.assignments -match $Group.id}
  89. #Write-host "Number of Device Compliance policies found: $($AllDeviceCompliance.DisplayName.Count)" -ForegroundColor cyan
  90. Foreach ($Config in $DeviceCompliance) {
  91.  
  92. Write-host $Config.displayName -ForegroundColor Yellow
  93.  
  94. }
  95.  
  96.  
  97. # Device Configuration
  98. If ($($DeviceConfig.DisplayName.Count) -gt 0)
  99. {
  100. Write-host "Number of Device Configurations found: $($DeviceConfig.DisplayName.Count)" -ForegroundColor magenta
  101. }
  102. #$AllDeviceConfig = Get-IntuneDeviceConfigurationPolicy -Select id, displayName, lastModifiedDateTime, assignments -Expand assignments | Where-Object {$_.assignments -match $Group.id}
  103. #Write-host "Number of Device Configurations found: $($AllDeviceConfig.DisplayName.Count)" -ForegroundColor cyan
  104. Foreach ($Config in $DeviceConfig) {
  105.  
  106. Write-host $Config.displayName -ForegroundColor Yellow
  107.  
  108. }
  109.  
  110. # Device Configuration Powershell Scripts
  111. If ($($DeviceConfigScripts.DisplayName.Count) -gt 0)
  112. {
  113. Write-host "Number of Device Configurations Powershell Scripts found: $($DeviceConfigScripts.DisplayName.Count)" -ForegroundColor magenta
  114. }
  115. Foreach ($Config in $DeviceConfigScripts) {
  116.  
  117. Write-host $Config.displayName -ForegroundColor Yellow
  118.  
  119. }
  120.  
  121.  
  122. # Administrative templates
  123. If ($($ADMT.DisplayName.Count) -gt 0)
  124. {
  125. Write-host "Number of Device Administrative Templates found: $($ADMT.DisplayName.Count)" -ForegroundColor magenta
  126. }
  127. Foreach ($Config in $ADMT) {
  128.  
  129. Write-host $Config.displayName -ForegroundColor Yellow
  130.  
  131. }
  132.  
  133. # Settings Catalogs
  134. If ($($ADMT.DisplayName.Count) -gt 0)
  135. {
  136. Write-host "Number of Settings Catalogs found: $($SC.DisplayName.Count)" -ForegroundColor magenta
  137. }
  138. Foreach ($Config in $ADSC) {
  139.  
  140. Write-host $Config.Name -ForegroundColor Yellow
  141.  
  142. }
  143.  
  144.  
  145.  
  146. if (($($AssignedApps.DisplayName.Count) -gt 0) -or ($($DeviceCompliance.DisplayName.Count) -gt 0) -or ($($DeviceConfig.DisplayName.Count) -gt 0) -or ($($DeviceConfigScripts.DisplayName.Count) -gt 0) -or ($($ADMT.DisplayName.Count) -gt 0) -or ($($SC.DisplayName.Count) -gt 0))
  147. {
  148. Write-Host ""
  149. Write-Host ""
  150. }
  151.  
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement