Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
directorcia committed Nov 5, 2024
1 parent 97d280c commit 7176b91
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions mggraph-ssdescpt-get.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
param( ## if no parameter used then login without MFA and use interactive mode
[switch]$debug = $false, ## if -debug parameter capture log information
[switch]$prompt = $false ## if -prompt parameter used prompt user for input
)
<# CIAOPS
Script provided as is. Use at own risk. No guarantees or warranty provided.
Expand All @@ -6,7 +10,7 @@ Description - Get all items from tenant secure score
Source - https://github.com/directorcia/Office365/blob/master/mggraph-ssdescpt-get.ps1
Prerequisites = 1
1. Install MSGRAph module - https://www.powershellgallery.com/packages/Microsoft.Graph/
1. Install MSGraph module - https://www.powershellgallery.com/packages/Microsoft.Graph/
More scripts available by joining http://www.ciaopspatron.com
Expand All @@ -15,25 +19,47 @@ More scripts available by joining http://www.ciaopspatron.com
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"

## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force

Clear-Host

start-transcript "..\mggraph-ssdescpt-get $(get-date -f yyyyMMddHHmmss).txt" ## write output file to parent directory
if ($debug) {
write-host -foregroundcolor $processmessagecolor "Script activity logged at ..\mggraph-ssdescpt-get.txt"
start-transcript "..\mggraph-ssdescpt-get.txt"
}

write-host -foregroundcolor $systemmessagecolor "Script started`n"

# Check if the Microsoft Graph module is installed
try {
$context = get-mgcontext -ErrorAction Stop
}
catch {
write-host -foregroundcolor $errormessagecolor "Not connected to Microsoft Graph. Please connect to Microsoft Graph first using connect-mggraph`n"
if ($prompt) {stop-transcript}
exit
}
if (-not $context) {
write-host -foregroundcolor $errormessagecolor "Not connected to Microsoft Graph. Please connect to Microsoft Graph first using connect-mggraph`n"
if ($prompt) {stop-transcript}
exit
}

write-host -foregroundcolor $processmessagecolor "Connected to Microsoft Graph"
write-host " - Connected account =",$context.Account,"`n"
if ($prompt) { pause }

# Specify the URI to call and method
$uri = "https://graph.microsoft.com/beta/security/securescores"
$method = "GET"

write-host -foregroundcolor $processmessagecolor "Run Graph API Query"
# Run Graph API query
$query = Invoke-MgGraphRequest -Uri $URI -method GET -ErrorAction Stop
$query = Invoke-MgGraphRequest -Uri $URI -method $method -ErrorAction Stop

$names = $query.value[0].controlscores
$names = $query.value[0].controlscores # get the most current secure score results

$item = 0
write-host -foregroundcolor $processmessagecolor "Display results`n"
Expand All @@ -49,7 +75,8 @@ foreach ($control in $names) {
write-host "Score in percentage : ", $control.scoreinpercentage
write-host "Last synced : ", $control.lastsynced
write-host "`n"
if ($prompt) { pause }
}
write-host -foregroundcolor $systemmessagecolor "`nScript Completed`n"

stop-transcript
if ($prompt) {stop-transcript}

0 comments on commit 7176b91

Please sign in to comment.