Profile.ps1 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ## vim
  2. New-Alias -Name vi -Value 'C:\Program Files (x86)\vim\vim82\vim.exe'
  3. New-Alias -Name vim -Value 'C:\Program Files (x86)\vim\vim82\vim.exe'
  4. ## readline
  5. Set-PSReadLineOption -EditMode Emacs
  6. Set-PSReadlineKeyHandler -Key Tab -Function Complete
  7. Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
  8. Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
  9. ## du function
  10. Function du {
  11. gci . | %{$f=$_; gci -r -file $_.FullName | measure-object -property length -sum | select @{Name="Name"; Expression={$f}}, @{Name="Sum (MB)"; Expression={"{0:N3}" -f ($_.sum / 1MB) }}, Sum } | sort Sum -desc |format-table -Property Name,"Sum (MB)", Sum -autosize
  12. }
  13. ## Mute Function
  14. Function Toggle-Mute(){$wshShell = new-object -com wscript.shell;$wshShell.SendKeys([char]173)}
  15. ## Admin test
  16. Function Test-IsAdmin {
  17. $user = [Security.Principal.WindowsIdentity]::GetCurrent();
  18. (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
  19. }
  20. ## Modify title if admin
  21. Function Admin-Test {
  22. ## From https://serverfault.com/a/95464
  23. $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  24. $IsAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  25. if(-not ($IsAdmin))
  26. {$Host.ui.RawUI.WindowTitle = "Regular User PowerShell"}
  27. else {$Host.ui.RawUI.WindowTitle = "**ADMIN** User PowerShell!"}
  28. }
  29. Admin-Test
  30. ## func to read chrome history
  31. ## set $username manually?
  32. function get-chromehistory {
  33. $path = "$env:systemdrive\users\$username\appdata\local\google\chrome\user data\default\history"
  34. if (-not (test-path -path $path)) {
  35. write-verbose "[!] could not find chrome history for username: $username"
  36. }
  37. $regex = '(htt(p|s))://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
  38. $value = get-content -path "$env:systemdrive\users\$username\appdata\local\google\chrome\user data\default\history"|select-string -allmatches $regex |% {($_.matches).value} |sort -unique
  39. $value | foreach-object {
  40. $key = $_
  41. if ($key -match $search){
  42. new-object -typename psobject -property @{
  43. user = $username
  44. browser = 'chrome'
  45. datatype = 'history'
  46. data = $_
  47. }
  48. }
  49. }
  50. }