-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utilities.ps1
31 lines (28 loc) · 981 Bytes
/
Utilities.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
# This script is referenced by the setup scripts. No need to run it
# manually.
Function Assert-Administrator {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if(!($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
throw 'This script must be run as an administrator.'
}
}
Function Assert-CommandExists([string]$CommandName) {
$Old = $ErrorActionPreference;
try {
$ErrorActionPreference = "stop";
if (Get-Command $CommandName) {
Return $true;
}
Return $false;
} catch {
Return $false;
} finally {
$ErrorActionPreference = $Old;
}
}
function Set-RegistryDword([string]$Path, [string]$Name, [int]$Value) {
If (!Test-Path $Path) {
New-Item -Path $Path -ItemType Directory | Out-Null
}
Set-ItemProperty -Path $Path -Name $Name -Type DWord -Value $Value
}