Skip to content

Commit 2c64bd9

Browse files
committed
update collector logic
1 parent e11eea5 commit 2c64bd9

1 file changed

Lines changed: 10 additions & 62 deletions

File tree

core/collector/Select-MonkeyCollector.ps1

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Function Select-MonkeyCollector{
4444
[String[]]$Service
4545
)
4646
Begin{
47+
#Set empty arrays
48+
$allCollectors = [System.Collections.Generic.List[System.Management.Automation.PSObject]]::new()
4749
$collectors = [System.Collections.Generic.List[System.Management.Automation.PSObject]]::new()
4850
Try{
4951
$services = $null;
@@ -54,12 +56,17 @@ Function Select-MonkeyCollector{
5456
}
5557
#Set params
5658
$p = @{
57-
Service = $services;
5859
InformationAction = $O365Object.InformationAction;
5960
Verbose = $O365Object.verbose;
6061
Debug = $O365Object.debug;
6162
}
63+
IF($null -ne $services){
64+
[void]$p.Add('Service',$services);
65+
}
6266
IF($PSBoundParameters.ContainsKey('Provider') -and $PSBoundParameters['Provider']){
67+
If($PSBoundParameters['Provider'].ToLower() -eq 'entraid'){
68+
return
69+
}
6370
[void]$p.Add('Provider',$PSBoundParameters['Provider']);
6471
}
6572
$allCollectors = Get-MetadataFromCollector @p
@@ -80,17 +87,6 @@ Function Select-MonkeyCollector{
8087
Tags = @('Monkey365ConnectorError');
8188
}
8289
Write-Error @msg
83-
#Set empty array
84-
$allCollectors = [System.Collections.Generic.List[System.Management.Automation.PSObject]]::new()
85-
}
86-
#Get Api Type
87-
Try{
88-
$useMsGraph = [System.Convert]::ToBoolean($O365Object.internal_config.entraId.useMsGraph)
89-
$useAADOldAPIForUsers = [System.Convert]::ToBoolean($O365Object.internal_config.entraId.getUsersWithAADInternalAPI)
90-
}
91-
Catch{
92-
$useMsGraph = $true;
93-
$useAADOldAPIForUsers = $false;
9490
}
9591
}
9692
Process{
@@ -115,15 +111,14 @@ Function Select-MonkeyCollector{
115111
#Check if EntraID collectors should be added
116112
If($O365Object.IncludeEntraID -eq $true -and $O365Object.onlineServices.EntraID -eq $true){
117113
$entraIdCollectors = [System.Collections.Generic.List[System.Object]]::new()
118-
$graphCollectors = Get-MetadataFromCollector -Provider EntraID -ApiType graphlegacy
119114
$msGraphCollectors = Get-MetadataFromCollector -Provider EntraID -ApiType MSGraph
120115
$apiPortalCollectors = Get-MetadataFromCollector -Provider EntraID -ApiType EntraIDPortal
121116
#Add Azure collector to get Diagnostic settings for Entra ID
122117
$eidCollector = Get-MetadataFromCollector -Provider Azure -Service General | Where-Object {$_.Id -eq "az00150"}
123118
If($null -ne $eidCollector){
124119
[void]$entraIdCollectors.Add($eidCollector);
125120
}
126-
If($O365Object.isConfidentialApp -eq $true){
121+
If($O365Object.isConfidentialApp){
127122
#Only MSGraph is supported for confidential apps
128123
If ($msGraphCollectors -is [System.Collections.IEnumerable] -and $msGraphCollectors -isnot [string]){
129124
[void]$entraIdCollectors.AddRange($msGraphCollectors)
@@ -132,26 +127,7 @@ Function Select-MonkeyCollector{
132127
[void]$entraIdCollectors.Add($msGraphCollectors)
133128
}
134129
}
135-
ElseIf($useMsGraph -eq $false -and $O365Object.isConfidentialApp -eq $false){
136-
#Load Old Graph collectors
137-
If ($graphCollectors -is [System.Collections.IEnumerable] -and $graphCollectors -isnot [string]){
138-
[void]$entraIdCollectors.AddRange($graphCollectors)
139-
}
140-
ElseIf ($graphCollectors.GetType() -eq [System.Management.Automation.PSCustomObject] -or $graphCollectors.GetType() -eq [System.Management.Automation.PSObject]) {
141-
[void]$entraIdCollectors.Add($graphCollectors)
142-
}
143-
#Load Entra ID internal API collectors
144-
If ($apiPortalCollectors -is [System.Collections.IEnumerable] -and $apiPortalCollectors -isnot [string]){
145-
[void]$entraIdCollectors.AddRange($apiPortalCollectors)
146-
}
147-
ElseIf ($apiPortalCollectors.GetType() -eq [System.Management.Automation.PSCustomObject] -or $apiPortalCollectors.GetType() -eq [System.Management.Automation.PSObject]) {
148-
[void]$entraIdCollectors.Add($apiPortalCollectors)
149-
}
150-
}
151-
ElseIf($useMsGraph -and $O365Object.isConfidentialApp -eq $false){
152-
Foreach($_collector in $entraIdCollectors.GetEnumerator()){
153-
[void]$collectors.Add($eidCollector);
154-
}
130+
Else{
155131
#Load MSGraph collectors
156132
If ($msGraphCollectors -is [System.Collections.IEnumerable] -and $msGraphCollectors -isnot [string]){
157133
[void]$entraIdCollectors.AddRange($msGraphCollectors)
@@ -166,34 +142,6 @@ Function Select-MonkeyCollector{
166142
ElseIf ($apiPortalCollectors.GetType() -eq [System.Management.Automation.PSCustomObject] -or $apiPortalCollectors.GetType() -eq [System.Management.Automation.PSObject]) {
167143
[void]$entraIdCollectors.Add($apiPortalCollectors)
168144
}
169-
#Check if should load old AAD collector for users
170-
If($useAADOldAPIForUsers){
171-
#Remove MSGraph user collector
172-
$entraIdCollectors = $entraIdCollectors.Where({$_.collectorName -ne "Get-MonkeyAADUser"});
173-
#Add graph users collector
174-
$OlduserCollector = @($graphCollectors).Where({$_.collectorName -eq "Get-MonkeyADUser"});
175-
If($OlduserCollector.Count -gt 0){
176-
Foreach($_collector in $OlduserCollector){
177-
[void]$entraIdCollectors.Add($_collector)
178-
}
179-
}
180-
#Add policies
181-
$policiesCollector = @($graphCollectors).Where({$_.collectorName -eq "Get-MonkeyADPolicy"});
182-
If($policiesCollector.Count -gt 0){
183-
Foreach($_collector in $policiesCollector){
184-
[void]$entraIdCollectors.Add($_collector)
185-
}
186-
}
187-
}
188-
}
189-
Else{
190-
#Load MSGraph collectors
191-
If ($msGraphCollectors -is [System.Collections.IEnumerable] -and $msGraphCollectors -isnot [string]){
192-
[void]$entraIdCollectors.AddRange($msGraphCollectors)
193-
}
194-
ElseIf ($msGraphCollectors.GetType() -eq [System.Management.Automation.PSCustomObject] -or $msGraphCollectors.GetType() -eq [System.Management.Automation.PSObject]) {
195-
[void]$entraIdCollectors.Add($msGraphCollectors)
196-
}
197145
}
198146
#Add discovered collectors
199147
Foreach($eidCollector in $entraIdCollectors.GetEnumerator()){

0 commit comments

Comments
 (0)