-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathMicrosoft.PowerShell_profile.ps1
103 lines (78 loc) · 3.18 KB
/
Microsoft.PowerShell_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
# Note foreach can be a keyword or an alias to foreach-object
# https://stackoverflow.com/questions/29148462/difference-between-foreach-and-foreach-object-in-powershell
# Set-ExecutionPolicy unrestricted
# So we can launch pwsh in subshells if we need
Add-PathVariable "${env:ProgramFiles}\PowerShell\6-preview"
$profileDir = $PSScriptRoot;
# From https://serverfault.com/questions/95431/in-a-powershell-script-how-can-i-check-if-im-running-with-administrator-privil#97599
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Edit whole dir, so we can edit included files etc
function edit-powershell-profile {
edit $profileDir
}
function update-powershell-profile {
& $profile
}
# https://blogs.technet.microsoft.com/heyscriptingguy/2012/12/30/powertip-change-the-powershell-console-title
function set-title([string]$newtitle) {
$host.ui.RawUI.WindowTitle = $newtitle + ' – ' + $host.ui.RawUI.WindowTitle
}
# From http://stackoverflow.com/questions/7330187/how-to-find-the-windows-version-from-the-powershell-command-line
function get-windows-build {
[Environment]::OSVersion
}
function disable-windows-search {
Set-Service wsearch -StartupType disabled
stop-service wsearch
}
# http://mohundro.com/blog/2009/03/31/quickly-extract-files-with-powershell/
# and https://stackoverflow.com/questions/1359793/programmatically-extract-tar-gz-in-a-single-step-on-windows-with-7zip
# function expand-archive([string]$file, [string]$outputDir = '') {
# if (-not (Test-Path $file)) {
# $file = Resolve-Path $file
# }
# $baseName = get-childitem $file | select-object -ExpandProperty "BaseName"
# if ($outputDir -eq '') {
# $outputDir = $baseName
# }
# # Check if there's a tar inside
# # We use the .net method as this file (x.tar) doesn't exist!
# $secondExtension = [System.IO.Path]::GetExtension($baseName)
# $secondBaseName = [System.IO.Path]::GetFileNameWithoutExtension($baseName)
# if ( $secondExtension -eq '.tar' ) {
# # This is a tarball
# $outputDir = $secondBaseName
# write-output "Output dir will be $outputDir"
# 7z x $file -so | 7z x -aoa -si -ttar -o"$outputDir"
# return
# }
# # Just extract the file
# 7z x "-o$outputDir" $file
# }
set-alias unzip expand-archive
function get-path {
($Env:Path).Split(";")
}
function Test-FileInSubPath([System.IO.DirectoryInfo]$Child, [System.IO.DirectoryInfo]$Parent) {
write-host $Child.FullName | select-object '*'
$Child.FullName.StartsWith($Parent.FullName)
}
function stree {
$SourceTreeFolder = get-childitem ("${env:LOCALAPPDATA}" + "\SourceTree\app*") | Select-Object -first 1
& $SourceTreeFolder/SourceTree.exe -f .
}
function get-serial-number {
Get-CimInstance -ClassName Win32_Bios | select-object serialnumber
}
function get-process-for-port($port) {
Get-Process -Id (Get-NetTCPConnection -LocalPort $port).OwningProcess
}
foreach ( $includeFile in ("aws", "defaults", "openssl", "aws", "unix", "development", "node") ) {
Unblock-File $profileDir\$includeFile.ps1
. "$profileDir\$includeFile.ps1"
}
set-location '~/Code'
write-output 'Mike profile loaded.'