Skip to content

Instantly share code, notes, and snippets.

@waldekmastykarz
Created June 1, 2021 12:02
Show Gist options
  • Select an option

  • Save waldekmastykarz/82846388f8b88176f63f73d2f1f0256f to your computer and use it in GitHub Desktop.

Select an option

Save waldekmastykarz/82846388f8b88176f63f73d2f1f0256f to your computer and use it in GitHub Desktop.
Removes granted SharePoint API permissions
#!/usr/bin/env zx
$.verbose = false;
console.log('Retrieving granted API permissions...');
const apiPermissions = JSON.parse(await $`m365 spo sp grant list -o json`);
for (let i = 0; i < apiPermissions.length; i++) {
const permission = apiPermissions[i];
console.log(`Removing permission ${permission.Resource}/${permission.Scope} (${permission.ObjectId})...`);
try {
await $`m365 spo serviceprincipal grant revoke --grantId ${permission.ObjectId}`
console.log(chalk.green('DONE'));
}
catch (err) {
console.error(err.stderr);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment