-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPSProfile.Functions.ps1
More file actions
269 lines (213 loc) · 7.08 KB
/
PSProfile.Functions.ps1
File metadata and controls
269 lines (213 loc) · 7.08 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# ---------------------------------------------------------------------
# PowerShell Profile - Custom Functions
# ---------------------------------------------------------------------
Function Update-Environment {
Refresh-Profile
Refresh-Path
Refresh-Module
Refresh-Function
Refresh-Alias
Refresh-Variable
}
Function Invoke-ProfileReload {
& $PROFILE
}
Function Get-PublicIP {
(Invoke-WebRequest 'http://ifconfig.me/ip' ).Content
}
Function Get-Timestamp {
Get-Date -Format u
}
Function Get-RandomPassword {
$length = 16
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+'
-join ((0..$length) | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] })
}
Function Update-WinGet {
Params(
[Switch]$Admin,
[Switch]$Interactive
)
if (Get-PSResource -Name WingetTools -ErrorAction SilentlyContinue) {
Import-Module WingetTools
} else {
Install-Module WingetTools -Force -SkipPublisherCheck
}
if ($Admin) {
} else {
winget upgrade --all
}
}
Function Update-Chocolatey {}
Function Update-Scoop {}
Function Update-R {}
Function Update-Python {}
Function Update-Node {}
Function Update-Pip {}
Function Update-Windows {}
Function Mount-DevDrive {
if (-not(Test-Path -Path 'X:\')) {
if (Get-PSDrive -Name 'Dev' -ErrorAction SilentlyContinue) {
Write-Host 'Mapped PSDrive for DevDrive already exists. Aborting Mounting...' -ForegroundColor Yellow
Return
} else {
$cmd = "sudo powershell.exe -Command 'Mount-VHD -Path I:\DevDrive\DevDrive.vhdx'"
try {
Write-Verbose 'Mounting DevDrive...'
Invoke-Expression -Command $cmd
} catch {
Write-Warning 'Failed to mount DevDrive...'
}
Write-Verbose 'Creating DevDrive PSDrive...'
New-PSDrive -Name 'Dev' -PSProvider FileSystem -Root 'X:\' -Scope Global
}
}
}
Function Set-LocationDesktop {
Set-Location -Path "$env:USERPROFILE\Desktop"
}
Function Set-LocationDownloads {
Set-Location -Path "$env:USERPROFILE\Downloads"
}
Function Set-LocationDocuments {
Set-Location -Path "$env:USERPROFILE\Documents"
}
Function Set-LocationPictures {
Set-Location -Path "$env:USERPROFILE\Pictures"
}
Function Set-LocationMusic {
Set-Location -Path "$env:USERPROFILE\Music"
}
Function Set-LocationVideos {
Set-Location -Path "$env:USERPROFILE\Videos"
}
Function Set-LocationDevDrive {
Set-Location -Path 'Dev:'
}
Function cd... {
Set-Location -Path '..\..'
}
Function cd.... {
Set-Location -Path '..\..\..'
}
Function Get-MD5Hash { Get-FileHash -Algorithm MD5 $args }
Function Get-SHA1Hash { Get-FileHash -Algorithm SHA1 $args }
Function Get-SHA256Hash { Get-FileHash -Algorithm SHA256 $args }
Function Invoke-Notepad { notepad.exe $args }
# Drive shortcuts
function HKLM: { Set-Location HKLM: }
function HKCU: { Set-Location HKCU: }
function Env: { Set-Location Env: }
if (Test-Path HKCU:\SOFTWARE\Microsoft\OneDrive) {
$onedrive = Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive
if (Test-Path $onedrive.UserFolder) {
New-PSDrive -Name OneDrive -PSProvider FileSystem -Root $onedrive.UserFolder -Description 'OneDrive'
function OneDrive: { Set-Location OneDrive: }
}
Remove-Variable onedrive
}
Function Invoke-Admin {
if ($args.Count -gt 0) {
$argList = "& '" + $args + "'"
Start-Process "$PSHOME\pwsh.exe" -Verb runAs -ArgumentList $argList
} else {
Start-Process "$PSHOME\pwsh.exe" -Verb RunAs
}
}
Function Edit-PSProfile {
$cmd = "$Env:Editor $PROFILE.CurrentUserAllHosts"
Invoke-Expression -Command $cmd
}
Function Edit-PSProfileProject {
if (-not($ProfileRootPath)) {
Write-Warning 'ProfileRootPath not found.'
$Global:ProfileRootPath = Split-Path -Path $PROFILE -Parent
}
$cmd = "$Env:Editor $ProfileRootPath"
Invoke-Expression -Command $cmd
}
Function Invoke-WingetUpdate {
Import-Module WingetTools
}
# Get-ProfileFunctions: Lists all custom functions in the current PowerShell profile.
Function Get-PSProfileFunctions {
<#
.SYNOPSIS
Lists all custom functions in the current PowerShell profile.
.DESCRIPTION
Lists all custom functions in the current PowerShell profile.
.EXAMPLE
Get-ProfileFunctions
.NOTES
Author: Jimmy Briggs <jimmy.briggs@jimbrig.com>
#>
$Functions = @(
[PSCustomObject]@{
Name = 'Get-PSProfileFunctions'
Description = 'Lists all custom functions in the current PowerShell profile.'
Alias = 'psprofilefunctions'
}
[PSCustomObject]@{
Name = 'Get-PSProfileModules'
Description = 'Lists all loaded modules in the current PowerShell profile.'
Alias = 'psprofilemodules'
}
[PSCustomObject]@{
Name = 'Update-Environment'
Description = 'Updates the current environment.'
Alias = 'refreshenv'
}
[PSCustomObject]@{
Name = 'Invoke-ProfileReload'
Description = 'Reloads the current PowerShell profile.'
Alias = 'reloadpsprofile'
}
[PSCustomObject]@{
Name = 'Get-PublicIP'
Description = 'Gets the public IP address of the current machine.'
Alias = 'publicip'
}
[PSCustomObject]@{
Name = 'Get-Timestamp'
Description = 'Gets the current timestamp.'
Alias = 'timestamp'
}
[PSCustomObject]@{
Name = 'Get-RandomPassword'
Description = 'Generates a random password.'
Alias = 'randompassword'
}
[PSCustomObject]@{
Name = 'Update-WinGet'
Description = 'Updates the Windows Package Manager (WinGet).'
Alias = 'updatewinget'
}
[PSCustomObject]@{
Name = 'Update-Chocolatey'
Description = 'Updates the Chocolatey Package Manager.'
Alias = 'updatechoco'
}
[PSCustomObject]@{
Name = 'Update-Scoop'
Description = 'Updates the Scoop Package Manager.'
Alias = 'updatescoop'
}
[PSCustomObject]@{
Name = 'Update-R'
Description = 'Updates the R Programming Language.'
Alias = 'updater'
}
[PSCustomObject]@{
Name = 'Update-Python'
Description = 'Updates the Python Programming Language.'
Alias = 'updatepython'
}
[PSCustomObject]@{
Name = 'Update-Node'
Description = 'Updates the Node.js JavaScript Runtime.'
Alias = 'updatenode'
}
)
Write-Host 'PowerShell Profile Custom Functions:' -ForegroundColor Cyan
$Functions | Format-Table -AutoSize
}