-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.ps1
154 lines (128 loc) · 6.31 KB
/
profile.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
#======================================================================================
# Enable TLS 1.2
#======================================================================================
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#======================================================================================
# Set console color scheme
#======================================================================================
#New-Item HKCU:\Console\%systemroot%_System32_WindowsPowerShell_v1.0_powershell.exe -force | Set-ItemProperty -Name ColorTable00 -Value 0x00562401 -PassThru | Set-ItemProperty -Name ColorTable07 -Value 0x00f0edee
$console = $host.ui.rawui
$console.BackgroundColor = 'Black'
$console.ForegroundColor = 'White'
$colors = $Host.PrivateData
$colors.ErrorForegroundColor = 'Red'
$colors.ErrorBackgroundColor = 'Black'
$colors.WarningForegroundColor = 'Yellow'
$colors.WarningBackgroundColor = 'Black'
$colors.DebugForegroundColor = 'Yellow'
$colors.DebugBackgroundColor = 'Black'
$colors.VerboseForegroundColor = 'Green'
$colors.VerboseBackgroundColor = 'Black'
$colors.ProgressForegroundColor = 'Gray'
$colors.ProgressBackgroundColor = 'Black'
Clear-Host
#======================================================================================
# Ctrl-Tab to show matching commands/available parameters
#======================================================================================
Set-PSReadlineKeyHandler -Chord CTRL+Tab -Function Complete
Set-PSReadlineOption -ShowToolTips -BellStyle Visual
#======================================================================================
# General Helper Functions
#======================================================================================
function reboot { shutdown /r /t 5 }
function halt { shutdown /s /t 5 }
function here { Invoke-Item . }
function Find-Files ([string] $glob) { get-childitem -recurse -include $glob }
function Remove-Directory ([string] $glob) { remove-item -recurse -force $glob }
Function Edit-Profile() { vsc $PROFILE.AllUsersAllHosts }
#======================================================================================
# Start Elevated session
#======================================================================================
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent()
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function Start-PsElevatedSession {
#Open a new elevated powershell window
If ( ! (Test-Administrator) ) {
start-process powershell -Verb runas
}
Else { Write-Warning "Session is already elevated" }
}
#======================================================================================
# 'Go' command and targets
#======================================================================================
$GLOBAL:go_locations = @{ }
if ( $GLOBAL:go_locations -eq $null ) {
$GLOBAL:go_locations = @{ }
}
function Go ([string] $location) {
if ( $go_locations.ContainsKey($location) ) {
set-location $go_locations[$location];
}
else {
write-output "The following locations are defined:";
write-output $go_locations;
}
}
$go_locations.Add("home", (get-item ([environment]::GetFolderPath("MyDocuments"))).Parent.FullName)
$go_locations.Add("desktop", [environment]::GetFolderPath("Desktop"))
$go_locations.Add("dl", ((New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path))
$go_locations.Add("docs", [environment]::GetFolderPath("MyDocuments"))
$go_locations.Add("scripts", "C:\Scripts")
#======================================================================================
# Custom prompt
#======================================================================================
function Global:Prompt {
$Time = Get-Date -Format "HH:mm"
$Directory = (Get-Location).Path
Write-Host "[$((Get-History).Count + 1)] " -NoNewline
Write-Host "[$Time] " -ForegroundColor Yellow -NoNewline
Write-Host "$Directory >" -NoNewline
return " "
}
#======================================================================================
# Define aliases
#======================================================================================
Set-Alias -name su -Value Start-PsElevatedSession
Set-Alias -name npp -Value Notepad++.exe
Set-Alias -name vsc -value code
Set-Alias -Name ff -Value Find-Files
Set-Alias -Name rmd -value Remove-Directory
Set-Alias -name ih -value invoke-history
#======================================================================================
# Final execution
#======================================================================================
Set-ExecutionPolicy RemoteSigned -Force
Go scripts
#======================================================================================
# Some Sysadmin sillyness
#======================================================================================
$block = @"
. . . . . . . . . + .
. . : . .. :. .___---------___.
. . . . :.:. _".^ .^ ^. '.. :"-_. . ADMINISTRATIVE WORKSTATION
. : . . .:../: . .^ :.:\.
. . :: +. :.:/: . . . . . .:\ Logged in user: $(whoami)
. : . . _ :::/: . ^ . . .:\ Elevated Privileges: $(Test-Administrator)
.. . . . - : :.:./. . .:\
. . . :..|: . . ^. .:|
. . : : ..|| . . . !:|
. . . . ::. ::\( . :)/
. . : . : .:.|. ###### .#######::|
:.. . :- : .: ::|.####### ..########:|
. . . .. . .. :\ ######## :######## :/
. .+ :: : -.:\ ######## . ########.:/
. .+ . . . . :.:\. ####### #######..:/
:: . . . . ::.:..:.\ . . ..:/
. . . .. : -::::.\. | | . .:/
. : . . .-:.":.::.\ ..:/
. -. . . . .: .:::.:.\. .:/
. . . : : ....::_:..:\ ___. :/
. . . .:. .. . .: :.:.:\ :/
+ . . : . ::. :.:. .:.|\ .:/|
. + . . ...:: ..| --.:|
. . . . . . . ... :..:.."( ..)"
. . . : . .: ::/ . .::\
"@
Write-Host $block -ForegroundColor Green