-
Notifications
You must be signed in to change notification settings - Fork 1
/
PSHelperFunctions.psm1
50 lines (44 loc) · 1.16 KB
/
PSHelperFunctions.psm1
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
# An assortment of helper functions that are useful in the CAT/MCECS environment.
Function Test-32Bit {
return [IntPtr]::size -eq 4
}
Function Assert-32Bit {
$Is32Bit = Test-32Bit
if (-not $is32Bit) { throw "Shell is not 32-bit.`n" }
return $Is32Bit
}
Function Test-64Bit {
return [IntPtr]::size -eq 8
}
Function Assert-64Bit {
$Is64Bit = Test-64Bit
if (-not $is64Bit) { throw "Shell is not 64-bit.`n" }
return $Is64Bit
}
Function Assert-CompIsOnline {
param(
[String]$ComputerName
)
$online = Test-Connection -ComputerName $ComputerName -Count 1 -Quiet
if (-not $online) { throw "Computer $ComputerName is not on.`n" }
}
Function Get-DomainlessUserName {
param(
[String]$UserName
)
$UserName -match '^\w+\\(.+)' | Out-Null
$user = $UserName
if ($Matches) { $user = $Matches[1] }
return $user
}
Function Invoke-32bitFunction {
param(
[ScriptBlock]$ScriptBlock
)
if (Test-32Bit) {
$Expr = "&$ScriptBlock"
} else {
$Expr = "$env:SystemRoot\SYSWOW64\WindowsPowerShell\v1.0\powershell.exe {$ScriptBlock}"
}
return (Invoke-Expression $Expr)
}