Skip to content

Commit

Permalink
Better CSV "formatting"
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelCaldasMS committed May 28, 2022
1 parent b1f8765 commit ece8143
Showing 1 changed file with 121 additions and 136 deletions.
257 changes: 121 additions & 136 deletions ssspider.ps1
Original file line number Diff line number Diff line change
@@ -1,123 +1,108 @@
Write-Output "Warning: the authentication window may be under the current window..."
Write-Output "Warning: the authentication window may be under the 'Current Score' window..."
$c = Connect-AzAccount -WarningAction SilentlyContinue
if (!$c) {
Write-Output "Not connected, exiting."
Exit
}

Write-Output "Connected."
$ts = Get-AzTenant | Select-Object Id, Name, @{l = "DomainNames"; e = {$d = "$($_.Domains)".Replace(" ", ", "); if ($d.Length -Le 50) {$d} else {"$($d.Substring(0, 47))..."}}}
$ts = Get-AzTenant | Select-Object Id, Name, @{l = "Domain Names"; e = {$d = "$($_.Domains)".Replace(" ", ", "); if ($d.Length -Le 50) {$d} else {"$($d.Substring(0, 47))..."}}}
if ($ts.Count -Eq 0) {
Write-Output "No tenants accessible by this user, exiting."
Exit
}

$ssl = @()
$ssl += [PSCustomObject]@{
tenantName = "Tenant Name"
domainNames = "Domain Names"
tenantId = "Tenant ID"
subscriptionName = "Subscription Name"
subscriptionId = "Subscription Id"
global = "Global"
component = "Component"
current = "Current"
max = "Max"
percent = "Percent"
weight = "Weight"
healthyResources = "Healthy Resources"
unhealthyResources = "Unhealthy Resources"
}

foreach ($t in $ts) {
$ss = Get-AzSubscription -TenantId $t.Id | Select-Object Id, Name
if ($ss.Count -Ne 0) {
Write-Output """$($t.Name)"", ""$($t.DomainNames)"", $($t.Id)"
Write-Output """$($t.Name)"", ""$($t.'Domain Names')"", $($t.Id)"
$ssl += [PSCustomObject]@{
tenantName = "$($t.Name)"
domainNames = "$($t.DomainNames)"
tenantId= "$($t.Id)"
subscriptionName = ""
subscriptionId = ""
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = "$($t.Name)"
'Domain Names' = "$($t.'Domain Names')"
'Tenant Id' = "$($t.Id)"
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
foreach ($s in $ss) {
Write-Output " ""$($s.Name)"", $($s.Id)"
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = "$($s.Name)"
subscriptionId = "$($s.Id)"
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = "$($s.Name)"
'Subscription Id' = "$($s.Id)"
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
Select-AzSubscription -Tenant $t.Id -Subscription $s.Id | Out-Null
$ss = Get-AzSecuritySecureScore | Select-Object DisplayName, CurrentScore, MaxScore, @{l = "Percent"; e = {"$([Math]::Round($_.Percentage*100, 2))%"}}, Weight
if (!$ss) {
Write-Output " Secure Score inacessible by this user."
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = "Secure Score inacessible by this user."
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = "Secure Score inacessible by this user."
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
} else {
Write-Output " $($ss.DisplayName) - Current: $($ss.CurrentScore), Max: $($ss.MaxScore), Percent: $($ss.Percent), Weight: $($ss.Weight)"
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = ""
global = "$($ss.DisplayName)"
component = ""
current = "$($ss.CurrentScore)"
max = "$($ss.MaxScore)"
percent = "$($ss.Percent)"
weight = "$($ss.Weight)"
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = "$($ss.DisplayName)"
'Component Name' = ""
'Current Score' = "$($ss.CurrentScore)"
'Maximum Score' = "$($ss.MaxScore)"
Percentage = "$($ss.Percent)"
Weight = "$($ss.Weight)"
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
$sscs = Get-AzSecuritySecureScoreControl | Select-Object DisplayName, CurrentScore, MaxScore, @{l = "Percent"; e = {"$([Math]::Round($_.Percentage*100, 2))%"}}, Weight, HealthyResourceCount, UnhealthyResourceCount
foreach ($ssc in $sscs) {
Write-Output " $($ssc.DisplayName) - Current: $($ssc.CurrentScore), Max: $($ssc.MaxScore), Percent: $($ssc.Percent), Weight: $($ssc.Weight), Healthy Resources: $($ssc.HealthyResourceCount), Unhealthy Resources: $($ssc.UnhealthyResourceCount)"
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = ""
global = ""
component = "$($ssc.DisplayName)"
current = "$($ssc.CurrentScore)"
max = "$($ssc.MaxScore)"
percent = "$($ssc.Percent)"
weight = "$($ssc.Weight)"
healthyResources = "$($ssc.HealthyResourceCount)"
unhealthyResources = "$($ssc.UnhealthyResourceCount)"
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = "$($ssc.DisplayName)"
'Current Score' = "$($ssc.CurrentScore)"
'Maximum Score' = "$($ssc.MaxScore)"
Percentage = "$($ssc.Percent)"
Weight = "$($ssc.Weight)"
'Healthy Resources' = "$($ssc.HealthyResourceCount)"
'Unhealthy Resources' = "$($ssc.UnhealthyResourceCount)"
}
}
}
Expand All @@ -131,67 +116,67 @@ foreach ($t in $ts) {
if ($emptyTenantsNotYetFound) {
Write-Output "No subscriptions accessible by this user under this(ese) tenant(s)."
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = ""
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
$ssl += [PSCustomObject]@{
tenantName = "No subscriptions accessible by this user under this(ese) tenant(s)."
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = ""
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = "No subscriptions accessible by this user under this(ese) tenant(s)."
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
$ssl += [PSCustomObject]@{
tenantName = ""
domainNames = ""
tenantId = ""
subscriptionName = ""
subscriptionId = ""
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = ""
'Domain Names' = ""
'Tenant Id' = ""
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
$emptyTenantsNotYetFound = $False
}
Write-Output " ""$($t.Name)"", ""$($t.DomainNames)"", $($t.Id)"
Write-Output " ""$($t.Name)"", ""$($t.'Domain Names')"", $($t.Id)"
$ssl += [PSCustomObject]@{
tenantName = "$($t.Name)"
domainNames = "$($t.DomainNames)"
tenantId = "$($t.Id)"
subscriptionName = ""
subscriptionId = ""
global = ""
component = ""
current = ""
max = ""
percent = ""
weight = ""
healthyResources = ""
unhealthyResources = ""
'Tenant Name' = "$($t.Name)"
'Domain Names' = "$($t.'Domain Names')"
'Tenant Id' = "$($t.Id)"
'Subscription Name' = ""
'Subscription Id' = ""
'Score Name' = ""
'Component Name' = ""
'Current Score' = ""
'Maximum Score' = ""
Percentage = ""
Weight = ""
'Healthy Resources' = ""
'Unhealthy Resources' = ""
}
}
}
Expand Down

0 comments on commit ece8143

Please sign in to comment.