Write a ms graph powershell script to take a list of group names and delete them from…
- User
Write a ms graph powershell script to take a list of group names and delete them from Entra
Assistant
# Script to delete Entra ID groups using Microsoft Graph param( [Parameter(Mandatory=$true)] [string]$GroupListFile ) # Import required module Import-Module Microsoft.Graph.Groups # Connect to Microsoft Graph with required permissions Connect-MgGraph -Scopes "Group.ReadWrite.All" # Check if file exists if (-not (Test-Path -Path $GroupListFile)) { Write-Host "Error: Group list file not found: $GroupListFile" -ForegroundColor Red exit } # Read group names from file $groupNames = Get-Content -Path $GroupListFile # Display confirmation Write-Host "This script will delete the following groups from Entra ID:" -ForegroundColor Yellow $groupNames | ForEach-Object { Write-Host " - $_" -ForegroundColor Yellow } $confirmation = Read-Host "Are you sure you want to proceed? (Y/N)" if ($confirmation -ne "Y") { Write-Host "Operation cancelled." -ForegroundColor Cyan exit } # Process each group foreach ($groupName in $groupNames) { Write-Host "Processing: $groupName" try { # Find the group by display name $group = Get-MgGroup -Filter "displayName eq '$groupName'" if ($null -eq $group) { Write-Host " Group not found: $groupName" -ForegroundColor Yellow continue } if ($group.Count -gt 1) { Write-Host " Multiple groups found with name '$groupName'. Skipping." -ForegroundColor Yellow continue } # Delete the group Remove-MgGroup -GroupId $group.Id Write-Host " Successfully deleted: $groupName" -ForegroundColor Green } catch { Write-Host " Error deleting group $groupName : $_" -ForegroundColor Red } } Write-Host "Group deletion process completed." -ForegroundColor Cyan
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.