-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
87 lines (77 loc) · 2.99 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
87 lines (77 loc) · 2.99 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
Set-Location C:\
Set-PSReadlineKeyHandler -Key Tab -Function Complete
New-Alias -Name npp -Value "C:\Program Files\Notepad++\notepad++.exe"
#Window Title
[System.Security.Principal.WindowsPrincipal]$global:currentUser =
New-Object System.Security.Principal.WindowsPrincipal(
[System.Security.Principal.WindowsIdentity]::GetCurrent()
)
if($global:currentUser.IsInRole(
[System.Security.Principal.WindowsBuiltInRole]::Administrator)
) {
$user = $global:currentUser.Identities.Name + " (Administrator)";
} else {
$user = $global:currentUser.Identities.Name
}
(Get-Host).UI.RawUI.WindowTitle = $user + " on " + [System.Net.Dns]::GetHostName() + " (v" + (Get-Host).Version + ")";
#Prompt
#function Prompt {
# Write-Host ("[") -nonewline -foregroundcolor White
# Write-Host (Get-Date -format HH:mm:ss) -nonewline -foregroundcolor White
# Write-Host ("]") -nonewline -foregroundcolor White
# Write-Host ($ENV:Username.tolower()) -nonewline -foregroundcolor DarkGray
# Write-Host ("@") -nonewline -foregroundcolor Green
# Write-Host ($ENV:COMPUTERNAME.tolower()) -NoNewline -ForegroundColor DarkGray
# #Write-Host ("]") -nonewline -foregroundcolor Green
# #Write-Host ("
# #") -NoNewline
# Write-Host ($executionContext.SessionState.Path.CurrentLocation) -NoNewline -ForegroundColor White
# Write-Host (">") -NoNewline -ForegroundColor White
# Return " ";
#}
(Get-PSProvider -PSProvider FileSystem).Home = $env:USERPROFILE
Function Prompt {
If ([bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).Groups -match 'S-1-5-32-544')) {
$Symbol = '#'
} Else {
$Symbol = '$'
}
$pdate = (Get-Date -format HH:mm:ss)
#$Prompt = "[$pdate] $($env:USERNAME.ToLower())@$($env:COMPUTERNAME.ToLower()) $Symbol "
$Prompt = "[$pdate] $($env:COMPUTERNAME.ToLower()) $Symbol "
$Host.UI.RawUI.WindowTitle = $Prompt
$Prompt
}
#Session logging
$PoSHLog = "C:\PortableApps\ConEmu\Transcripts\PSSessionLog_$(Get-Date -Format MMddyyyy).log"
Start-Transcript -Path $PoSHLog -Append
#Checks if PoSH session is being executed as Administrator
$WID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$Prp = New-Object System.Security.Principal.WindowsPrincipal($WID)
$Adm = [System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin = $Prp.IsInRole($Adm)
if( $IsAdmin ){
$Host.UI.RawUI.Backgroundcolor = "DarkRed"
Clear-Host
}
# Start PowerShell As Domain Admin
Function Start-PowerShellAsAdmin {
$Credential = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList "domain\username",(Get-Content "$($env:userprofile)\filename_priv.txt" | ConvertTo-SecureString)
Start-Process PowerShell -LoadUserProfile -Credential $Credential
}
#Creates a new file if it does not exist or updates the timestamp if it does exist
Function touch
{
$file = $args[0]
if($file -eq $null) {
throw "No filename supplied"
}
if(Test-Path $file)
{
(Get-ChildItem $file).LastWriteTime = Get-Date
}
else
{
echo $null > $file
}
}