forked from tomtorggler/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_profile.ps1
128 lines (111 loc) · 4.16 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
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
#######
### The actual $PROFILE only contains the following line to dot-source this file
### . $env:USERPROFILE\Git\PowerShell\Microsoft.PowerShell_profile.ps1
######
$host.PrivateData.ErrorForegroundColor = 'white'
## Aliases... because of muscle memory :/
New-Alias -Name ll -Value Get-ChildItem -ErrorAction SilentlyContinue
function Invoke-AsAdmin {
param($command)
Start-Process pwsh -Verb RunAs -ArgumentList "-noprofile $command"
}
function Set-DnsOpen {
param(
$InterfaceIndex = 4
)
$command = "Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ServerAddresses ('208.67.222.222','208.67.220.220','2620:0:ccc::2','2620:0:ccd::2')"
Invoke-AsAdmin $command
}
function Set-DnsCloudflare {
param(
$InterfaceIndex = 4
)
$command = "Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ServerAddresses ('1.1.1.1','1.0.0.1','2606:4700:4700::1111','2606:4700:4700::1001')"
Invoke-AsAdmin $command
}
function Set-DnsDhcp {
param(
$InterfaceIndex = 4
)
$command = "Set-DnsClientServerAddress -InterfaceIndex $InterfaceIndex -ResetServerAddresses"
Invoke-AsAdmin $command
}
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
dir "$env:USERPROFILE\Git\IT-Pro-Trashcan\tto\tools" -Filter *.ps1 | %{ . $_.FullName }
Set-SecurityProtocol -Protocol Tls12
$connectedIf = Get-NetRoute -DestinationPrefix 0.0.0.0/0 | Sort-Object -Property RouteMetric -Descending
if($connectedIf){
$dnsServers = (Get-DnsClientServerAddress -InterfaceIndex $connectedIf.IfIndex | Select-Object -ExpandProperty serveraddresses -Unique) -join ", "
}
$write = "
---
IfAlias: $(($connectedIf.InterfaceAlias | Select-Object -Unique) -join ", ")
IfIndex: $(($connectedIf.IfIndex | Select-Object -Unique) -join ", ")
DNS Servers: $dnsServers
Security Protcols: $(Get-SecurityProtocol)
---
"
Write-Host $write -ForegroundColor Yellow
function prompt {
$pss = Get-PSSession | Where-Object Availability
$cwd = (Get-Location).Path
if($pss) {
$WindowTitle = "Connected to: " + ($pss.ComputerName -join ", ")
$info = $pss.ComputerName -join ", "
$info += ": #$($MyInvocation.HistoryId)"
} else {
$WindowTitle = $cwd
$info = "PS: #$($MyInvocation.HistoryId)"
}
if($Global:WindowTitlePrefix){
$WindowTitle = $Global:WindowTitlePrefix,$WindowTitle -join ": "
}
$host.UI.RawUI.WindowTitle = $WindowTitle
$host.UI.Write("Yellow", $host.UI.RawUI.BackGroundColor, "[$info]")
" $($cwd.Replace($env:USERPROFILE,"~"))$('>' * ($nestedPromptLevel + 1)) ";
}
function Set-WindowTitle($String) {
$Global:WindowTitlePrefix = $String
}
function Get-JekyllTitle {
[CmdletBinding()]
param (
[string]
$String
)
process {
$date = Get-Date -Format "yyyy-MM-dd"
$date,($string.ToLower() -replace "\W+","-") -join "-"
}
}
# check if a new release of PowerShell Core is available on GitHub
function Test-PSVersionGitHub {
try {
# get latest release from github atom feed
$Release = Invoke-RestMethod https://github.com/PowerShell/PowerShell/releases.atom -ErrorAction Stop | Select-Object -First 1
} catch {
Write-Warning "Could not check for new version. $_ `n"
break
}
# extract information from atom response
$GitId = $Release.id -split "/" | Select-Object -Last 1
$Download = -join("https://github.com",$Release.link.href)
# Add information to dictionary for output
$output = [ordered]@{
"PSVersion" = $PSVersionTable.PSVersion;
"GitCommitId" = $PSVersionTable.GitCommitId;
"GitHubReleaseVersion" = $GitId;
"GitHubReleaseLink" = $Download;
}
if($output.PSVersion -ne $output.GitCommitId){
Write-Output (New-Object -TypeName psobject -Property $output)
}
}
if($iscoreclr){
Test-PSVersionGitHub
}
$env:Path += ";C:\Users\ThomasTorggler\OneDrive - Experts Inside AG\Tools"