Skip to content

Instantly share code, notes, and snippets.

@jhoneill
Last active February 13, 2021 12:18
Show Gist options
  • Save jhoneill/d3f75d8438c821dbe06d155827902ab8 to your computer and use it in GitHub Desktop.
Save jhoneill/d3f75d8438c821dbe06d155827902ab8 to your computer and use it in GitHub Desktop.
#I created this to show how much there is on the MS Graph API.
#I pulled down the openapi (nee swagger) files for Users, users.actions, Users,functions and groups
#And using my https://github.com/jhoneill/PSGraph - my version of Kevin Marquette's graphViz Module
#this litte bit of script produced a graphical version
$paths = @()
$ParentHash = @{}
function hasParent {
# .synopsis if the parent isn't in the call recursively with the parent. Add item and its parent to the hash
param($path)
if ($path -notmatch "/") { return}
$parent = $path -replace '^(.*)/.+?$','$1'
if (-not $ParentHash[$parent]) {hasParent $parent }
$ParentHash[$path] = $parent ; return $Path
}
#foreach yaml file get the root (servers in the yaml) and each path under paths
#to keep the view simple
#filter out if we got too many levels deep end with $ref, or branches which have a 2nd ID
dir *.yml | ForEach-Object {
$y = convertfrom-yaml (Get-Content $_ -Raw)
#top is the same in all the files so this over-write won't matter
$top = $y.servers.url -replace '/$', ''
$ParentHash[$top] = $true
$paths += $y.paths.Keys |
Where-Object {($_ -notmatch '/\$\w+$') -and
($_ -notmatch 'id1\}/') -and (
($_ -split '/').count -lt 10) } |
ForEach-Object { hasParent( $top + $_)} |
Sort-Object
}
# remove duplicates.
$paths = $paths | Sort-Object -unique
graph -Name g -Attributes @{rankdir="LR"; } -ScriptBlock {
#create root node
node -name $top -Attributes @{
label = ($top);
shape = 'folder'; fontname = 'Segoe UI';
style = 'filled'; fillcolor = 'lightyellow'; }
#for all the paths, add a node which is the last part of the path and link to their parent
foreach ($p in $paths) {
node -Name $p -Attributes @{
label = ($p -split "/")[-1]
shape = 'folder'; fontname = 'Segoe UI'
style ='filled' ; fillcolor='lightyellow' }
edge -NodeName ($p -replace '^(.*)/.+?$','$1') `
-To $p
}
} | Export-PSGraph -ShowGraph -OutputFormat jpg
# this will output to a temporary file and open it. Change the type as needed.
@jhoneill
Copy link
Author

UsersGroupsDirObjects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment