-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSTenableSCSupport.ps1
135 lines (118 loc) · 3.65 KB
/
PSTenableSCSupport.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Import localization data.
Import-LocalizedData -BindingVariable local -FileName PSTenableSCLocal -UICulture en-US
#region set globally accessible variables.
# Get local dateTime format.
$Global:LocalDatePattern = ((Get-Culture).DateTimeFormat).ShortDatePattern + " " + (((Get-Culture)).DateTimeFormat).LongTimePattern
# New line.
$Global:NewLine = [Environment]::NewLine
#endregion
Function ConvertFrom-EpochToNormal {
<#
.SYNOPSIS
Epoc time conversion support function.
.DESCRIPTION
Convert epoch time to readable format.
.EXAMPLE
Convert epoch time to readable format.
ConvertFrom-EpochToNormal -InputEpoch 1548752112
.EXAMPLE
Convert epoch time to readable format in one of the available locales.
ConvertFrom-EpochToNormal -InputEpoch 1548752112
.PARAMETER InputEpoch
Enter epoch time.
.PARAMETER DateFormat
Choose one of the available locales.
.FUNCTIONALITY
Converts epoch time to readable format.
#>
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $True, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[Int]$InputEpoch
)
# Convert epoch time to readable format, using local date time format.
Get-Date ([TimeZone]::CurrentTimeZone.ToLocalTime(([DateTime]'1.1.1970').AddSeconds($InputEpoch))) -Format "$LocalDatePattern"
}
Function ConvertFrom-NormalToEpoch {
<#
.SYNOPSIS
Normal time to epoch conversion support function.
.DESCRIPTION
Convert normal time to epoch.
.EXAMPLE
Convert from normal time to epoch with current UTC time.
ConvertFrom-NormalToEpoch
.EXAMPLE
Convert from normal time to epoch with supplied UTC time.
ConvertFrom-NormalToEpoch -Date "01.01.2016"
.PARAMETER InputEpoch
Enter time. It will be automatically converted to UTC.
.FUNCTIONALITY
Converts normal time to epoch.
#>
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $False, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[DateTime]$Date = (Get-Date)
)
# Convert normal time to epoch.
([DateTimeOffset](Get-Date $Date -Format "$LocalDatePattern")).ToUnixTimeSeconds()
}
Function Write-SCLog {
<#
.SYNOPSIS
Logging support function.
.DESCRIPTION
Shows verbose info when -Verbose switch is used, showing extensive info on executed cmdlets.
.EXAMPLE
A simple example:
Write-SCLog -LogInfo "This is an important message"
.EXAMPLE
An example with localization:
Write-SCLog -LogInfo $local.GET_IP
.EXAMPLE
An example with localization using a variable:
Write-SCLog -LogInfo $($local.GET_IP $IP)
.PARAMETER LogInfo
Specify log info.
.NOTES
Output will be formatted as: "datetime - LogInfo"
.FUNCTIONALITY
Provides verbose information for debugging purposes.
#>
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $True, HelpMessage = { $local.SCLOG_HELP_LOGINFO })]
[String]$LogInfo
)
# Get current datetime and store it into a variable.
$DateStamp = Get-Date -Format "dd.MM.yyyy HH:mm:ss"
# Output verbose log text.
Write-Verbose "$DateStamp - $LogInfo"
}
Function Write-SCError {
<#
.SYNOPSIS
Custom error notification function.
.DESCRIPTION
Shows custom error messages.
.EXAMPLE
A simple example:
Write-SCError -Message "You messed up!" -RecommendedAction "Fix it."
.PARAMETER Message
Let user know what went wrong.
.PARAMETER RecommendedAction
Let user know how to fix the error.
.FUNCTIONALITY
Provides cleaner error information to user.
#>
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $True, HelpMessage = { $local.SCERROR_HELP_MESSAGE })]
[String]$Message,
[Parameter(Position = 1, Mandatory = $True, HelpMessage = { $local.SCERROR_HELP_RECOMMENDED_ACTION })]
[String]$RecommendedAction
)
Write-Host -ForegroundColor Red -BackgroundColor Black -Object "Error: $Message$($NewLine)Recommended Action: $RecommendedAction"
Break
}