-
Notifications
You must be signed in to change notification settings - Fork 4
/
Setup.ps1
55 lines (46 loc) · 2.12 KB
/
Setup.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
47
48
49
50
51
52
53
54
55
[CmdletBinding(
SupportsShouldProcess=$true #Tells the shell that your function supports both -confirm and -whatif.
,ConfirmImpact="High" #Causes Confirm prompt when $ConfirmPreference is "High"
)]
param ()
if (!([bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544"))){
# http://superuser.com/questions/749243/detect-if-powershell-is-running-as-administrator
throw "Setup.ps1 requires administrative privelages."
}
#Install Pester
If(!(get-module Pester -ListAvailable)) {
If ($pscmdlet.ShouldProcess("Install Pester (https://github.com/pester/Pester)")) {
Install-Module Pester -verbose
}
}
# Note: This function is defined by Chocolatey as well but we have a script local version in case Chocolatey is not installed.
# Also, this version sets the session instance of the enviroment variable.
Function Script:Set-EnvironmentVariable {
[CmdletBinding(SupportsShouldProcess)]
param(
[ValidateScript({-not [string]::IsNullOrWhiteSpace($_)})][Parameter(Mandatory)][string]$Name,
[Parameter(Mandatory)][string]$Value,
[ValidateSet('User','Machine')][string]$Scope='User'
)
[string]$scopeArgs = $null
if($Scope -eq 'Machine') {
$scopeArgs = '/M'
}
setx.exe $Name $Value $scopeArgs | Out-Null
Set-Item -Path Env:$Name -Value $Value
}
$PSToolboxPath=Join-Path $PSScriptRoot Modules
if($env:PSModulePath -notlike "*$PSToolboxPath*") {
Script:Set-EnvironmentVariable -Name 'PSModulePath' -Value "$PSToolboxPath;$env:PSModulePath"
if($PSToolboxPath -notin ($env:PSModulePath -split ';')) {
Write-Host -foreground Cyan $PSToolboxPath
#NOTE: This does not test the change from [System.Environment]::SetEnvironmentVariable is permanent.
throw "PSModulePath ('$env:PSModulePath') is not set with $PSToolboxPath"
}
}
If(Test-Path variable:\psise) {
Function Test-CurrentFile {
Invoke-Pester $psISE.CurrentFile.FullPath.Replace(".Tests","").Replace(".ps1",".Tests.ps1");
}
Set-Alias Test Test-CurrentFile
}