Skip to content

Instantly share code, notes, and snippets.

@mendel129
Last active March 4, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mendel129/33bc020d25efd813950eabc56be373a9 to your computer and use it in GitHub Desktop.
Save mendel129/33bc020d25efd813950eabc56be373a9 to your computer and use it in GitHub Desktop.
# Mendel's PowerShell profile
# https://gist.github.com/mendel129/33bc020d25efd813950eabc56be373a9
set-alias -name npp 'C:\Program Files\Notepad++\notepad++.exe'
set-alias -name edit 'C:\Program Files\Notepad++\notepad++.exe'
set-alias -name notepad 'C:\Program Files\Notepad++\notepad++.exe'
set-alias -name wireshark "C:\Program Files\Wireshark\Wireshark.exe"
$profilepath = $env:USERPROFILE
function get-ipaddress
{
Get-NetIPAddress | ?{($_.interfacealias -notlike "*loopback*") -and ($_.interfacealias -notlike "*vmware*") -and ($_.interfacealias -notlike "*loopback*") -and ($_.interfacealias -notlike "*bluetooth*") -and ($_.interfacealias -notlike "*isatap*")} | ft
}
function reboot {shutdown -r -t 0}
function edit-profile {edit $profile}
function get-uptime
{
$lastBootTime=(Get-WmiObject win32_operatingsystem | select csname, @{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}).LastBootUpTime
$uptime = (Get-Date) - $lastBootTime
write-output "uptime: $uptime - last boot: $lastBootTime"
}
function elevate
{
$file, [string]$arguments = $args;
$psi = new-object System.Diagnostics.ProcessStartInfo $file;
$psi.Arguments = $arguments;
$psi.Verb = "runas";
$psi.WorkingDirectory = get-location;
[System.Diagnostics.Process]::Start($psi);
}
function set-staticip
{
netsh interface ipv4 set address name="DOCK" static 192.168.1.10 255.255.255.0
}
function set-dynamicip
{
netsh interface ipv4 set address name="DOCK" source=dhcp
}
function reload
{
Start-Process PowerShell -WorkingDirectory $env:USERPROFILE
exit
#. $profile
}
function isadmin
{
# Returns true/false
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
}
function enable-webcam
{
#Get-CimInstance Win32_PnPEntity | where PNPDeviceID -eq 'USB\VID_0C45&PID_6717&MI_00\6&65BCF92&0&0000'
if(isadmin)
{
Enable-PnpDevice 'USB\VID_0C45&PID_6717&MI_00\6&65BCF92&0&0000'
}
else
{
write-error "run me elevated"
}
}
function disable-webcam
{
if(isadmin)
{
Disable-PnpDevice 'USB\VID_0C45&PID_6717&MI_00\6&65BCF92&0&0000'
}
else
{
write-error "run me elevated"
}
}
function get-webcam
{
If((Get-PnpDevice 'USB\VID_0C45&PID_6717&MI_00\6&65BCF92&0&0000').Status -eq "Error")
{write-output "webcam disabled"}
If((Get-PnpDevice 'USB\VID_0C45&PID_6717&MI_00\6&65BCF92&0&0000').Status -eq "OK")
{write-output "webcam enabled"}
}
function DrawMenu {
## supportfunction to the Menu function below
param ($menuItems, $menuPosition, $menuTitel)
$fcolor = $host.UI.RawUI.ForegroundColor
$bcolor = $host.UI.RawUI.BackgroundColor
$l = $menuItems.length + 1
cls
$menuwidth = $menuTitel.length + 4
Write-Host "`t" -NoNewLine
Write-Host ("*" * $menuwidth) -fore $fcolor -back $bcolor
Write-Host "`t" -NoNewLine
Write-Host "* $menuTitel *" -fore $fcolor -back $bcolor
Write-Host "`t" -NoNewLine
Write-Host ("*" * $menuwidth) -fore $fcolor -back $bcolor
Write-Host ""
Write-debug "L: $l MenuItems: $menuItems MenuPosition: $menuposition"
for ($i = 0; $i -le $l;$i++) {
Write-Host "`t" -NoNewLine
if ($i -eq $menuPosition) {
Write-Host "$($menuItems[$i])" -fore $bcolor -back $fcolor
} else {
Write-Host "$($menuItems[$i])" -fore $fcolor -back $bcolor
}
}
}
function Menu {
## Generate a small "DOS-like" menu.
## Choose a menuitem using up and down arrows, select by pressing ENTER
param ([array]$menuItems, $menuTitel = "MENU")
$vkeycode = 0
$pos = 0
DrawMenu $menuItems $pos $menuTitel
While ($vkeycode -ne 13) {
$press = $host.ui.rawui.readkey("NoEcho,IncludeKeyDown")
$vkeycode = $press.virtualkeycode
Write-host "$($press.character)" -NoNewLine
If ($vkeycode -eq 38) {$pos--}
If ($vkeycode -eq 40) {$pos++}
If ($pos -lt 0) {$pos = $menuItems.length -1}
If ($pos -ge $menuItems.length) {$pos = 0}
DrawMenu $menuItems $pos $menuTitel
}
Write-Output $($menuItems[$pos])
}
write-host "Profile loaded" -backgroundcolor black -ForegroundColor red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment