Skip to content

Commit 714721f

Browse files
committed
Update module
1 parent 1f30a9f commit 714721f

3 files changed

Lines changed: 244 additions & 251 deletions

File tree

Invoke-Monkey365.ps1

Lines changed: 115 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -318,141 +318,137 @@ Function Invoke-Monkey365{
318318
[Switch]$ListFramework
319319
)
320320
dynamicparam{
321-
# Set available instance class
322-
$instance_class = @{
323-
Azure = $Script:azure_plugins
324-
Microsoft365 = $Script:m365_plugins
325-
}
326321
# set a new dynamic parameter
327-
$paramDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
322+
$paramDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new()
328323
# check to see whether the user already chose an instance
329-
if(Get-Variable -Name Instance -ErrorAction Ignore){
330-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
331-
# define a new parameter attribute
332-
$analysis_attr_name = New-Object System.Management.Automation.ParameterAttribute
333-
$analysis_attr_name.Mandatory = $false
334-
$attributeCollection.Add($analysis_attr_name)
335-
336-
# set the ValidateSet attribute
337-
$token_attr_name = New-Object System.Management.Automation.ValidateSetAttribute($instance_class.Item($Instance))
338-
$attributeCollection.Add($token_attr_name)
339-
340-
# create the dynamic -Collect parameter
341-
$analysis_pname = 'Collect'
342-
$analysis_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($analysis_pname,
343-
[Array], $attributeCollection)
344-
$paramDictionary.Add($analysis_pname, $analysis_type_dynParam)
324+
if ($PSBoundParameters.ContainsKey('Instance')) {
325+
$collectValues = switch ($PSBoundParameters['Instance']) {
326+
'Azure' {
327+
$script:azure_plugins
328+
}
329+
'Microsoft365' {
330+
$script:m365_plugins
331+
}
332+
default {
333+
@()
334+
}
335+
}
336+
if (-not $collectValues -or $collectValues.Count -eq 0) {
337+
return $paramDictionary
338+
}
339+
If ($collectValues -and $collectValues.Count -gt 0) {
340+
$paramDictionary.Add(
341+
'Collect',
342+
(New-DynamicParameter `
343+
-Name 'Collect' `
344+
-Type ([string[]]) `
345+
-ValidateSet ([string[]]$collectValues))
346+
)
347+
}
345348
}
346349
#Add parameters for Azure instance
347-
if($null -ne (Get-Variable -Name Instance -ErrorAction Ignore) -and $Instance -eq 'Azure'){
348-
#Create the -AllSubscriptions switch parameter
349-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
350-
# define a new parameter attribute
351-
$all_sbs_attr_name = New-Object System.Management.Automation.ParameterAttribute
352-
$all_sbs_attr_name.Mandatory = $false
353-
$attributeCollection.Add($all_sbs_attr_name)
354-
355-
#Create alias for -AllSubscriptions switch param
356-
$allsbs_alias = New-Object System.Management.Automation.AliasAttribute -ArgumentList 'all_subscriptions'
357-
$attributeCollection.Add($allsbs_alias)
358-
359-
$sbs_pname = 'AllSubscriptions'
360-
$analysis_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($sbs_pname,
361-
[switch], $attributeCollection)
362-
$paramDictionary.Add($sbs_pname, $analysis_type_dynParam)
363-
364-
#Create the -Subscriptions string parameter
365-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
366-
# define a new parameter attribute
367-
$sbs_attr_name = New-Object System.Management.Automation.ParameterAttribute
368-
$sbs_attr_name.Mandatory = $false
369-
$attributeCollection.Add($sbs_attr_name)
370-
371-
$sbs_pname = 'Subscriptions'
372-
$analysis_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($sbs_pname,
373-
[string], $attributeCollection)
374-
$paramDictionary.Add($sbs_pname, $analysis_type_dynParam)
375-
376-
#Create the -ResourceGroups string parameter
377-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
378-
# define a new parameter attribute
379-
$rg_attr_name = New-Object System.Management.Automation.ParameterAttribute
380-
$rg_attr_name.Mandatory = $false
381-
$attributeCollection.Add($rg_attr_name)
382-
383-
$rg_pname = 'ResourceGroups'
384-
$rg_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($rg_pname,
385-
[String[]], $attributeCollection)
386-
$paramDictionary.Add($rg_pname, $rg_type_dynParam)
387-
388-
#Create the -ExcludeResources File parameter
389-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
390-
# define a new parameter attribute
391-
$exclude_rsrc_attr_name = New-Object System.Management.Automation.ParameterAttribute
392-
$exclude_rsrc_attr_name.Mandatory = $false
393-
$attributeCollection.Add($exclude_rsrc_attr_name)
394-
395-
$rsrc_pname = 'ExcludedResources'
396-
$rsrc_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($rsrc_pname,
397-
[System.IO.FileInfo], $attributeCollection)
398-
$paramDictionary.Add($rsrc_pname, $rsrc_type_dynParam)
350+
If($PSBoundParameters.ContainsKey('Instance') -and $PSBoundParameters['Instance'] -eq 'Azure'){
351+
#Add AllSubscriptions parameter
352+
$paramDictionary.Add(
353+
'AllSubscriptions',
354+
(New-DynamicParameter `
355+
-Name 'AllSubscriptions' `
356+
-Type ([switch]) `
357+
-Alias 'all_subscriptions')
358+
)
359+
#Add Subscriptions parameter
360+
$paramDictionary.Add(
361+
'Subscriptions',
362+
(New-DynamicParameter `
363+
-Name 'Subscriptions' `
364+
-Type ([string]))
365+
)
366+
#Add ResourceGroups parameter
367+
$paramDictionary.Add(
368+
'ResourceGroups',
369+
(New-DynamicParameter `
370+
-Name 'ResourceGroups' `
371+
-Type ([string[]]))
372+
)
373+
#Add ResourceExclusionFile
374+
$paramDictionary.Add(
375+
'ExcludedResources',
376+
(New-DynamicParameter `
377+
-Name 'ExcludedResources' `
378+
-Type ([System.IO.FileInfo]) `
379+
-Alias 'excluded_resources')
380+
)
399381
}
400382
#Add parameters for Microsoft365 instance
401-
If($null -ne (Get-Variable -Name Instance -ErrorAction Ignore) -and $Instance -eq 'Microsoft365'){
402-
#Create the -SpoSites string parameter
403-
$attributeCollection = New-Object -TypeName System.Collections.ObjectModel.Collection[System.Attribute]
404-
# define a new parameter attribute
405-
$rg_attr_name = New-Object System.Management.Automation.ParameterAttribute
406-
$rg_attr_name.Mandatory = $false
407-
$attributeCollection.Add($rg_attr_name)
408-
$rg_pname = 'SpoSites'
409-
$rg_type_dynParam = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($rg_pname,
410-
[string[]], $attributeCollection)
411-
$paramDictionary.Add($rg_pname, $rg_type_dynParam)
383+
If($PSBoundParameters.ContainsKey('Instance') -and $PSBoundParameters['Instance'] -eq 'Microsoft365'){
384+
$paramDictionary.Add(
385+
'SpoSites',
386+
(New-DynamicParameter `
387+
-Name 'SpoSites' `
388+
-Type ([string[]]) `
389+
-Alias 'spo_sites'
390+
)
391+
)
412392
#Add PowerBI/Fabric ClientId parameter attribute
413-
$clientIdAttr = New-Object System.Management.Automation.ParameterAttribute
414-
$clientIdAttr.Mandatory = $false
415-
$clientIdAttrCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
416-
$clientIdAttrCollection.Add($clientIdAttr)
417-
$clientIdParam = New-Object System.Management.Automation.RuntimeDefinedParameter('PowerBIClientId', [System.String], $clientIdAttrCollection)
418-
$paramDictionary.Add('PowerBIClientId', $clientIdParam)
393+
$paramDictionary.Add(
394+
'PowerBIClientId',
395+
(New-DynamicParameter `
396+
-Name 'PowerBIClientId' `
397+
-Type ([string]) `
398+
-Alias 'powerbi_client_id'
399+
)
400+
)
419401
#Add PowerBI/Fabric Client Secret parameter attribute
420-
$clientSecretAttr = New-Object System.Management.Automation.ParameterAttribute
421-
$clientSecretAttr.Mandatory = $false
422-
$clientSecretAttrCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
423-
$clientSecretAttrCollection.Add($clientSecretAttr)
424-
$clientSecretParam = New-Object System.Management.Automation.RuntimeDefinedParameter('PowerBIClientSecret', [System.Security.SecureString], $clientSecretAttrCollection)
425-
$paramDictionary.Add('PowerBIClientSecret', $clientSecretParam)
402+
$paramDictionary.Add(
403+
'PowerBIClientSecret',
404+
(New-DynamicParameter `
405+
-Name 'PowerBIClientSecret' `
406+
-Type ([System.Security.SecureString]) `
407+
-Alias 'powerbi_client_secret'
408+
)
409+
)
426410
#Add PowerBI/Fabric PSCredential parameter attribute
427-
$pscredAttr = New-Object System.Management.Automation.ParameterAttribute
428-
$pscredAttr.Mandatory = $false
429-
$pscredAttrCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
430-
$pscredAttrCollection.Add($pscredAttr)
431-
$pscredParam = New-Object System.Management.Automation.RuntimeDefinedParameter('PowerBIClientCredentials', [System.Management.Automation.PSCredential], $pscredAttrCollection)
432-
$paramDictionary.Add('PowerBIClientCredentials', $pscredParam)
411+
$paramDictionary.Add(
412+
'PowerBIClientCredentials',
413+
(New-DynamicParameter `
414+
-Name 'PowerBIClientCredentials' `
415+
-Type ([System.Management.Automation.PSCredential]) `
416+
-Alias 'powerbi_client_credential'
417+
)
418+
)
433419
#Add PowerBI/Fabric Certificate parameter attribute
434-
$certFileAttr = New-Object System.Management.Automation.ParameterAttribute
435-
$certFileAttr.Mandatory = $false
436-
$certFileAttrCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
437-
$certFileAttrCollection.Add($certFileAttr)
438-
$validateScriptAttr = New-Object System.Management.Automation.ValidateScriptAttribute({ Test-Path -Path $_ -PathType Leaf })
439-
$certFileAttrCollection.Add($validateScriptAttr)
440-
$certFileParam = New-Object System.Management.Automation.RuntimeDefinedParameter('PowerBICertificateFile', [System.IO.FileInfo], $certFileAttrCollection)
441-
$paramDictionary.Add('PowerBICertificateFile', $certFileParam)
420+
$paramDictionary.Add(
421+
'PowerBICertificateFile',
422+
(New-DynamicParameter `
423+
-Name 'PowerBICertificateFile' `
424+
-Type ([System.IO.FileInfo]) `
425+
-Alias 'powerbi_certificate_file'
426+
)
427+
)
442428
#Add PowerBI/Fabric Certificate password parameter attribute
443-
$certPassAttr = New-Object System.Management.Automation.ParameterAttribute
444-
$certPassAttr.Mandatory = $false
445-
$certPassAttrCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
446-
$certPassAttrCollection.Add($certPassAttr)
447-
$passParam = New-Object System.Management.Automation.RuntimeDefinedParameter('PowerBICertificatePassword', [System.Security.SecureString], $certPassAttrCollection)
448-
$paramDictionary.Add('PowerBICertificatePassword', $passParam)
429+
$paramDictionary.Add(
430+
'PowerBICertificatePassword',
431+
(New-DynamicParameter `
432+
-Name 'PowerBICertificatePassword' `
433+
-Type ([System.Security.SecureString]) `
434+
-Alias 'powerbi_certificate_password'
435+
)
436+
)
449437
}
450438
# return the collection of dynamic parameters
451439
$paramDictionary
452440
}
453441
Begin{
454442
#Set Window name
455443
$Host.UI.RawUI.WindowTitle = "Monkey365 Cloud Security Scanner"
444+
#Import MSAL module
445+
$MSAL = Join-Path $Script:ScriptPath 'core/modules/monkeymsal'
446+
If (-not (Get-Module -Name monkeymsal)) {
447+
Import-Module $MSAL -ArgumentList $PSBoundParameters['ForceMsalDesktop']
448+
}
449+
#Import Cloud Utils module
450+
$cloudUtils = Join-Path $Script:ScriptPath 'core/modules/monkeycloudutils/monkeycloudutils.psd1'
451+
Import-Module -Name $cloudUtils
456452
#Start Time
457453
$starttimer = Get-Date
458454
#####Get Default parameters ########
@@ -462,8 +458,6 @@ Function Invoke-Monkey365{
462458
#Set timer
463459
$O365Object.startDate = $starttimer
464460
Update-PsObject
465-
#Initialize Logger
466-
Initialize-MonkeyLogger
467461
#Check if import job
468462
If($PSBoundParameters.ContainsKey('ImportJob') -and $PSBoundParameters.ImportJob){
469463
Import-MonkeyJob
@@ -582,19 +576,10 @@ Function Invoke-Monkey365{
582576
}
583577
return
584578
}
579+
#Initialize Logger
580+
Initialize-MonkeyLogger
585581
#Check for mandatory params
586582
Test-MandatoryParameter
587-
#Import MSAL module
588-
$msg = @{
589-
MessageData = "Importing MSAL authentication library";
590-
callStack = (Get-PSCallStack | Select-Object -First 1);
591-
logLevel = 'info';
592-
InformationAction = $O365Object.InformationAction;
593-
Tags = @('Monkey365LoadMSAL');
594-
}
595-
Write-Information @msg
596-
$MSAL = ("{0}{1}core/modules/monkeymsal" -f $O365Object.Localpath,[System.IO.Path]::DirectorySeparatorChar)
597-
Import-Module $MSAL -Force -ArgumentList $O365Object.forceMSALDesktop -Scope Global
598583
################### End Validate parameters #####################
599584
#Initialize authentication parameters
600585
Initialize-AuthenticationParam

monkey365.psd1

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,23 @@ RequiredModules = @()
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
6969
NestedModules = @(
70-
#'core/modules/monkeyutils/monkeyutils.psm1'
71-
#'core/modules/monkeylogger/monkeylogger.psm1'
70+
'core/modules/monkeyutils/monkeyutils.psm1'
71+
'core/modules/monkeylogger/monkeylogger.psm1'
72+
#'core/modules/monkeycloudutils/monkeycloudutils.psm1'
73+
'core/modules/monkeyhttpwebrequest/monkeyhttpwebrequest.psm1'
74+
'core/modules/psmarkdig/psmarkdig.psm1'
75+
'core/modules/monkeyhtml/monkeyhtml.psm1'
76+
'core/modules/monkeyjob/monkeyjob.psm1'
77+
'core/modules/monkeyruleset/monkeyruleset.psm1'
78+
'core/modules/psocsf/psocsf.psm1'
79+
'core/modules/monkeyoutput/monkeyoutput.psm1'
7280
)
7381

7482
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
7583
FunctionsToExport = @(
7684
'Invoke-Monkey365',
7785
'Get-MonkeyJobError',
78-
'Convert-MarkDownToHtml',
79-
'Convert-MarkDownToPlainText',
80-
'Copy-PsObject',
81-
'ConvertTo-SecureScriptBlock',
82-
'Update-PsObject',
83-
'Get-AstFunction',
84-
'Get-ObjectPropertyByPath',
85-
'Register-Monkey365Application',
86-
'Test-IsPsObject',
87-
'Get-HashFromString',
88-
'Get-MonkeyLatestReleaseFromGitHub'
86+
'Register-Monkey365Application'
8987
)
9088

9189
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

0 commit comments

Comments
 (0)