Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/powershell/Initialize-Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ function Initialize-Dependencies {
[Microsoft.PowerShell.Commands.ModuleSpecification[]]$externalModuleDependencies = $moduleManifest.PrivateData.ExternalModuleDependencies

[Microsoft.PowerShell.Commands.ModuleSpecification[]]$xPlatPowerShellRequiredModules = @(
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Az.Accounts'; GUID = '17a2feff-488b-47f9-8729-e2cec094624c'; ModuleVersion = '4.0.2'; },
@{ModuleName = 'ExchangeOnlineManagement'; GUID = 'b5eced50-afa4-455b-847a-d8fb64140a22'; RequiredVersion = '3.9.0'; }
)
Expand Down Expand Up @@ -178,6 +178,7 @@ function Initialize-Dependencies {
{
if ($saveModuleCmd.Name -eq 'Save-PSResource')
{
#TODO: use the find before piping result to Save-PSResource.
$saveModuleCmdParamsClone['Name'] = $moduleSpec.Name
# Save-PSResource uses NuGet version range syntax: https://learn.microsoft.com/en-us/nuget/concepts/package-versioning?tabs=semver20sort#version-ranges
if ($moduleSpec.RequiredVersion) {
Expand Down
6 changes: 3 additions & 3 deletions src/powershell/ZeroTrustAssessment.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ FunctionsToExport = 'Connect-ZtAssessment', 'Disconnect-ZtAssessment',
'Get-ZtExportStatistics', 'Get-ZtGraphScope', 'Get-ZtTest',
'Get-ZtTestStatistics', 'Invoke-ZtAssessment',
'Invoke-ZtGraphRequest', 'Invoke-ZtAzureRequest',
'Invoke-ZtAzureResourceGraphRequest'
'Invoke-ZtAzureResourceGraphRequest', 'Clear-ZtRequiredModule'

# 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.
CmdletsToExport = @()
Expand Down Expand Up @@ -104,8 +104,8 @@ PrivateData = @{
)

XPlatPowerShellRequiredModules = @(
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Az.Accounts'; GUID = '17a2feff-488b-47f9-8729-e2cec094624c'; ModuleVersion = '4.0.2'; },
@{ModuleName = 'ExchangeOnlineManagement'; GUID = 'b5eced50-afa4-455b-847a-d8fb64140a22'; RequiredVersion = '3.9.0'; }
)
Expand Down
43 changes: 43 additions & 0 deletions src/powershell/public/Clear-ZtRequiredModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
param ()

function Clear-ZtRequiredModule {
[CmdletBinding()]
param (
)

# If CallStack from the Module file (psm1), the module is being loaded.
if ((Get-PSCallStack).Position.File -like '*ZeroTrustAssessment.psm1')
{
Write-Verbose -Message 'Command is being called from module loading. Ignoring.'
return
}
elseif ($MyInvocation.MyCommand.Module) # Called when module is loaded.
{
Write-Warning -Message 'This command cannot be run when the module is loaded.'
Write-Warning -Message 'Please close all sessions where ZeroTrustAssessment module is loaded, then run the following...'
Write-Warning -Message ('&''{0}''' -f $PSCommandPath)
if ($isWindows -and (Get-Command -Name Set-Clipboard -ErrorAction SilentlyContinue)) {
Set-Clipboard -Value ('&''{0}''' -f $PSCommandPath)
Write-Warning -Message '(The command has been copied to your clipboard.)'
}
return
}
else
{
Write-Verbose -Message 'Clearing ZTA required modules from the current session.'
}

# Remove all ZTA-related modules from the current session
if ($isWindows) {
$ZTAModulesFolder = Join-Path -Path $Env:APPDATA -ChildPath 'ZeroTrustAssessment\Modules'
}
else {
$ZTAModulesFolder = Join-Path -Path $Env:HOME -ChildPath '.cache/ZeroTrustAssessment/Modules'
}

if (Test-Path -Path $ZTAModulesFolder) {
Remove-Item -Path $ZTAModulesFolder -Recurse -Force -ErrorAction Continue
}
}

Clear-ZtRequiredModule @PSBoundParameters
14 changes: 8 additions & 6 deletions src/powershell/public/Connect-ZtAssessment.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function Connect-ZtAssessment {
<#
.SYNOPSIS
Helper method to connect to Microsoft Graph using Connect-MgGraph with the required scopes.
Helper method to connect to Microsoft Graph and other services with the appropriate parameters
and scopes for the Zero Trust Assessment.

.DESCRIPTION
Use this cmdlet to connect to Microsoft Graph using Connect-MgGraph.
Use this cmdlet to connect to Microsoft Graph and other services using the appropriate parameters and scopes
for the Zero Trust Assessment.

This command is completely optional if you are already connected to Microsoft Graph and other services using Connect-MgGraph with the required scopes.

Expand Down Expand Up @@ -82,9 +84,9 @@ function Connect-ZtAssessment {
[switch]
$SkipAzureConnection,

# The services to connect to such as Azure and ExchangeOnline. Default is Graph.
# The services to connect to such as Azure and ExchangeOnline. Default is All.
[ValidateSet('All', 'Azure', 'AipService', 'ExchangeOnline', 'Graph', 'SecurityCompliance', 'SharePointOnline')]
[string[]]$Service = 'Graph',
[string[]]$Service = 'All',

# The Exchange environment to connect to. Default is O365Default. Supported values include O365China, O365Default, O365GermanyCloud, O365USGovDoD, O365USGovGCCHigh.
[ValidateSet('O365China', 'O365Default', 'O365GermanyCloud', 'O365USGovDoD', 'O365USGovGCCHigh')]
Expand Down Expand Up @@ -117,8 +119,8 @@ function Connect-ZtAssessment {
}

[Microsoft.PowerShell.Commands.ModuleSpecification[]]$xPlatPowerShellRequiredModules = @(
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.32.0'; },
@{ModuleName = 'Microsoft.Graph.Authentication'; GUID = '883916f2-9184-46ee-b1f8-b6a2fb784cee'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Microsoft.Graph.Beta.Teams'; GUID = 'e264919d-7ae2-4a89-ba8b-524bd93ddc08'; ModuleVersion = '2.35.1'; },
@{ModuleName = 'Az.Accounts'; GUID = '17a2feff-488b-47f9-8729-e2cec094624c'; ModuleVersion = '4.0.2'; },
@{ModuleName = 'ExchangeOnlineManagement'; GUID = 'b5eced50-afa4-455b-847a-d8fb64140a22'; RequiredVersion = '3.9.0'; }
)
Expand Down
Loading