All scripts
Automation 718
Get-MicrosoftGraphPermissions
Looks up exactly which Microsoft Graph permissions a given cmdlet (or every installed Graph module) actually needs, so you stop guessing scopes and getting 403s.
Get-MicrosoftGraphPermissions.ps1
# Author: Shehryar Hassan
# Source: HarmVeenstra/Powershellisfun (MIT License)
# https://github.com/HarmVeenstra/Powershellisfun/tree/main/Get%20Microsoft%20Graph%20Permissions
function Get-MicrosoftGraphPermissions {
param (
[parameter(Mandatory = $false, ParameterSetName = 'All')][switch]$All,
[Parameter(Mandatory = $false, ParameterSetName = 'Cmdlet')][String[]]$Cmdlet,
[Parameter(Mandatory = $false)][string]$Filename,
[Parameter(Mandatory = $false, ParameterSetName = 'Module')][String[]]$Module,
[Parameter(Mandatory = $false)][validateset('Console', 'ConsoleGridView', 'GridView')][string]$Output = 'Console'
)
#Check if required modules are installed for when using ConsoleGridView or XLSX
if ($Output -eq 'ConsoleGridView') {
if ($host.Version.Major -eq 7) {
if (-not (Get-Module Microsoft.PowerShell.ConsoleGuiTools -ListAvailable)) {
try {
Install-Module Microsoft.PowerShell.ConsoleGuiTools -Scope CurrentUser -ErrorAction Stop
Import-Module Microsoft.PowerShell.ConsoleGuiTools -ErrorAction Stop
Write-Host ('Installed missing PowerShell Module Microsoft.PowerShell.ConsoleGuiTools which is needed for ConsoleGridView output') -ForegroundColor Green
}
catch {
Write-Warning ('Could not install missing PowerShell Module Microsoft.PowerShell.ConsoleGuiTools which is needed for ConsoleGridView output, exiting...')
return
}
}
}
else {
Write-Warning ('The ConsoleGridView parameter only works on PowerShell v7, version {0} was found. Exiting...' -f $host.Version.Major)
return
}
}
#Build list of cmdlet(s) or all Microsoft Graph cmdlets to query
if ($all) {
$cmdlets = foreach ($item in (Get-Module Microsoft.Graph* -ListAvailable | Where-Object ModuleType -NE Manifest).ExportedCommands.Values) {
[PSCustomObject]@{
'Name' = $item.Name
'PowerShell Module Name' = $item.Source
'Version' = $item.Version
}
}
if ($null -eq $cmdlets) {
Write-Warning ('No Microsoft Graph Modules were not found, exiting...')
return
}
}
if ($Cmdlet -and -not $all) {
try {
$cmdlets = foreach ($item in Get-Command $cmdlet -ErrorAction Stop) {
[PSCustomObject]@{
'Name' = $item.Name
'PowerShell Module Name' = $item.Source
'Version' = $item.Version
}
}
}
catch {
Write-Warning ('One or more specified Cmdlets are not found, exiting...')
return
}
}
# ...full lookup logic continues in the source repo, trimmed here for length.
# See the repo_url above for the complete script (module filtering, XLSX/CSV
# export, and the Microsoft Graph permissions reference download).
}Read it before you run it, and test in a safe tenant first.