-
Notifications
You must be signed in to change notification settings - Fork 0
/
PogoCore.ps1
212 lines (155 loc) · 4.94 KB
/
PogoCore.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#################
# CONFIG #
#################
$block = [char]0x2588 # Block character for padding
$bar = [char]0x2500
$devMessage = "DevMode"
#################
# SYSTEM #
#################
[int]$timeout=10
function Stop-Computer {
Write-Host "**WARNING** Shutting down in $timeout seconds..." -ForegroundColor Red
Start-Sleep -Seconds $timeout
Start-Process "shutdown" -ArgumentList "/s /t 0"
}
function Exit-UserSession {
Write-Host "**WARNING** Logging out in $timeout seconds..." -ForegroundColor Red
Start-Sleep -Seconds $timeout
Write-Host "Logging out now" -ForegroundColor Green
Start-Process "logoff"
}
function Restart-Computer {
Write-Host "**WARNING** Restarting computer in $timeout seconds..." -ForegroundColor Red
Start-Sleep -Seconds $timeout
Write-Host "Restarting now" -ForegroundColor Green
Start-Process "shutdown" -ArgumentList "/r /t 0"
}
function Suspend-Computer {
Write-Host "**WARNING** Putting computer to sleep in $timeout seconds..." -ForegroundColor Yellow
Start-Sleep -Seconds $timeout
Start-Process rundll32.exe -ArgumentList "powrprof.dll,SetSuspendState Sleep"
}
function Show-AdvancedSystemProperties {
Write-Output "Starting System Properties...";
Start-Process "control" -ArgumentList "sysdm.cpl,,3"
}
function Show-PowerOptionsApplet {
Write-Output "Starting Power Configuration...";
Start-Process powercfg.cpl
}
function Get-Timestamp{
return (Get-Date).ToString("HH:mm")
}
function Get-Uptime{
$bootTime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime
$uptime = (Get-Date) - $bootTime
$uptimeHours = [math]::Round($uptime.TotalHours, 2)
return $uptimeHours
}
#################
# DISPLAY #
#################
function Get-HorizontalBar{
$str = "$bar$bar"
if ($devMode)
{
$str = $devMessage
}
$paddedString = $str.PadLeft(50 + $str.Length, $bar).PadRight(100, $bar)
return $paddedString
}
function Show-ColorList {
$List = [enum]::GetValues([System.ConsoleColor])
ForEach ($Color in $List){
Write-Host " $Color" -ForegroundColor $Color -NonewLine
Write-Host ""
} #end foreground color ForEach loop
ForEach ($Color in $List){
Write-Host " " -backgroundColor $Color -noNewLine
Write-Host " $Color"
} #end background color ForEach loop
}
function Show-ColorGrid
{
$colors = [enum]::GetValues([System.ConsoleColor])
Foreach ($bgcolor in $colors){
Foreach ($fgcolor in $colors) { Write-Host "$fgcolor|" -ForegroundColor $fgcolor -BackgroundColor $bgcolor -NoNewLine }
Write-Host " on $bgcolor"
}
}
function Switch-VolumeMute {
$obj = new-object -com wscript.shell
$obj.SendKeys([char]173)
}
#################
# NETWORK #
#################
function Get-WanIP {
try {
return (Invoke-WebRequest https://checkip.amazonaws.com/).Content.Trim()
} catch {
return "N/A"
}
}
function Get-LanIP {
try {
return (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.InterfaceAlias -eq $interfaceName }).IPAddress
} catch {
return "N/A"
}
}
function Get-dnsServers {
$dnsServers = (Get-DnsClientServerAddress -InterfaceAlias $interfaceName -AddressFamily IPv4).ServerAddresses -join ","
return $dnsServers
}
function Get-MacAddress {
$mac = (Get-NetAdapter | Where-Object { $_.Name -eq $interfaceName }).MacAddress
return ($mac -replace '-', ':').Trim()
}
function Get-IPGeoLocation {
param(
[string]$ipAddress,
[string]$fields = ""
)
# Check if the IP is already in the cache
if ($global:geoCache.ContainsKey($ipAddress)) {
return $global:geoCache[$ipAddress]
}
if (Test-IPv4Address $ipAddress) {
$url = "http://ip-api.com/json/${ipAddress}"
if ($fields -ne "") {
$url += "?fields=$fields"
}
$response = Invoke-RestMethod -Method Get -Uri $url
# Store the result in the cache
$global:geoCache[$ipAddress] = $response
return $response
} else {
return "Could not get IP geo location"
}
}
function Test-IPv4Address {
param (
[string]$ipAddress
)
if ($ipAddress -match '^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$') {
return $true
} else {
return $false
}
}
function Show-GeoCache {
# Hardcoded global geoCache variable
$geoCache = $global:geoCache
# Convert the hashtable to an array of custom objects for formatting
$cacheArray = @()
foreach ($key in $geoCache.Keys) {
$cacheArray += [PSCustomObject]@{
IPAddress = $key
CountryCode = $geoCache[$key].countryCode
}
}
# Display the cache in a table format
$cacheArray | Format-Table -AutoSize
}