-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.ps1
68 lines (55 loc) · 1.71 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$StatusInfo = @{
ErrorCount = $Global:Error.Count
ExecutedCommandCount = (Get-History).Count
LastExecutionStatus = $true
}
function Update-LastExecutionStatus {
$StatusInfo.LastExecutionStatus = ($Global:Error.Count -le $StatusInfo.ErrorCount) -and ($LASTEXITCODE -le 0)
$LASTEXITCODE = 0
}
function Update-ExecutedCommandCount {
$StatusInfo.ExecutedCommandCount = (Get-History).Count
}
function Update-ErrorCount {
$StatusInfo.ErrorCount = $Global:Error.Count
}
function Get-LastExecutionStatus {
return $StatusInfo.LastExecutionStatus
}
function Get-LastExecutedCommand {
$history = Get-History
return $history[$history.Count - 1]
}
function Test-IsElevated {
return $StatusInfo.IsElevated
}
function Test-HasNewExecutedCommand {
return (Get-History).Count -gt $StatusInfo.ExecutedCommandCount
}
function Get-CurrentDriveName {
return $(Get-Location).Drive.Name
}
function Get-CurrentDriveType {
return $(Get-Location).Drive.Provider.Name
}
function Get-CurrentPlatform {
return [System.Environment]::OSVersion.Platform
}
function CheckIdentity {
if ((Get-CurrentPlatform) -eq 'Win32NT') {
$identity = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
return $identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
} elseif ((Get-CurrentPlatform) -eq 'Unix') {
return $(whoami) -eq 'root'
}
}
$StatusInfo.IsElevated = CheckIdentity
Export-ModuleMember -Function @(
'Get-LastExecutionStatus',
'Get-LastExecutedCommand',
'Test-IsElevated',
'Test-HasNewExecutedCommand',
'Get-CurrentDriveName',
'Get-CurrentDriveType',
'Get-CurrentPlatform'
)