forked from OneIdentity/safeguard-ps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup-local.ps1
30 lines (27 loc) · 971 Bytes
/
cleanup-local.ps1
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
[CmdletBinding()]
Param(
[string]$TargetDir
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $TargetDir)
{
$TargetDir = [array]($env:PSModulePath -split ';') | Where-Object { $_.StartsWith($env:UserProfile) }
if($TargetDir.Count -eq 0)
{
throw "Unable to find a PSModulePath in your user profile (" + $env:UserProfile + "), PSModulePath: " + $env:PSModulePath
}
$TargetDir = $TargetDir[0]
}
if (-not (Test-Path $TargetDir))
{
New-Item -Path $TargetDir -ItemType Container -Force | Out-Null
}
$ModuleName = "safeguard-ps"
$ModuleDir = (Join-Path $TargetDir $ModuleName)
if (-not (Test-Path $ModuleDir))
{
New-Item -Path $ModuleDir -ItemType Container -Force | Out-Null
}
Remove-Item -Recurse -Force (Join-Path $ModuleDir "*")
Write-Host -ForegroundColor Yellow "$ModuleDir is now clean and you can run:"
Write-Host "`tInstall-Module safeguard-ps -Scope CurrentUser -Verbose"