-
Notifications
You must be signed in to change notification settings - Fork 27
/
cleanup-local.ps1
46 lines (42 loc) · 1.36 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[CmdletBinding()]
Param(
[string]$TargetDir
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $PSBoundParameters.ContainsKey("Verbose")) { $VerbosePreference = $PSCmdlet.GetVariableValue("VerbosePreference") }
if ($Env:OS -eq "Windows_NT")
{
$UserProf = $env:USERPROFILE
$Delim = ';'
}
else
{
$UserProf = $HOME
$Delim = ':'
}
if (-not $TargetDir)
{
$TargetDirs = [array]($env:PSModulePath -split $Delim)
$TargetDirs | ForEach-Object {
Write-Host "Potential target directory = '$_'"
}
$TargetDir = $TargetDirs | Where-Object { $_.StartsWith($UserProf) } | Select-Object -First 1
if (-not $TargetDir)
{
throw "Unable to find a PSModulePath in your user profile (" + $UserProf + "), PSModulePath: " + $env:PSModulePath
}
Write-Host "Selected target directory = '$TargetDir'"
}
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"