-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathClear-ZtRequiredModules.ps1
More file actions
41 lines (36 loc) · 1.44 KB
/
Clear-ZtRequiredModules.ps1
File metadata and controls
41 lines (36 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
param ()
function Clear-ZtRequiredModules {
[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)
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-ZtRequiredModules @PSBoundParameters