Skip to content

Instantly share code, notes, and snippets.

@juvtib
Last active March 14, 2021 21:38
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 juvtib/1f513217c126e8c4efeb646a03438a62 to your computer and use it in GitHub Desktop.
Save juvtib/1f513217c126e8c4efeb646a03438a62 to your computer and use it in GitHub Desktop.
$host.ui.rawui.WindowTitle = "Mike's PowerShell"
function prompt {
$logFile = "C:\Users\Michael\Documents\PowerShell Log.txt"
$lastCommand = get-history –count 1
if ($lastCommand)
{
# There is a command in history.
$whenDidItRun = Get-Date –Date $lastCommand.StartExecutionTime –Format 'yyyy MMMM dd HH:mm:ss'
$logEntry = "$whenDidItRun> $($lastCommand.CommandLine)"
Add-Content –Value $logEntry –Path $logFile
Write-Host $logEntry –ForegroundColor DarkGreen
"> "
}
else
{
# There is no command in history.
# You just opened PowerShell.
"> "
}
}
clear
# Quick Access
$qa = @{
bookmarklets = "~\Bookmarklets"
downloads = "~\Downloads"
desktop = "~\Desktop"
githubpages = "~\GitHub Site\source\juvtib.github.io"
journal = "~\Journal"
history = "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine"
nppApp = "$env:APPDATA\Notepad++"
stackoverflow = "~\Stack Overflow"
vim = "~\Desktop\Vim"
}
# Windows Build Information
# Appx – Import-Module: Operation is not supported on this platform. (0x80131539)
# https://github.com/PowerShell/PowerShell/issues/13138
# How do I find the version of my Windows Feature Experience Pack?
# https://stackoverflow.com/questions/64831517/how-do-i-find-the-version-of-my-windows-feature-experience-pack
Switch ($PSVersionTable.PSVersion.ToString())
{
"7.1.2" {Import-Module –Name Appx –UseWindowsPowerShell; Break}
}
$buildInfo = [PSCustomObject]@{
Version = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name DisplayVersion
InstalledOn = [DateTime]::FromFileTime((Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name InstallTime))
OSBuild = "{0}.{1}" -f (Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name CurrentBuild), (Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name UBR)
Edition = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name ProductName
ReleaseId = Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" –Name ReleaseId
Experience = (Get-AppxPackage 'MicrosoftWindows.Client.CBS').Version
}
New-Alias -Name hourglass -Value "C:\Program Files (x86)\Hourglass\Hourglass.exe"
New-Alias -Name notepad++ -Value "C:\Program Files (x86)\Notepad++\notepad++.exe"
New-Alias -Name paint -Value "C:\Program Files\paint.net\PaintDotNet.exe"
New-Alias -Name vim -Value "C:\Program Files (x86)\Vim\vim82\vim.exe"
function dryer { & "C:\Program Files (x86)\Hourglass\Hourglass.exe" --title "Dryer" "1h 10m" }
function duck ([string] $searchTerms)
{
Add-Type –AssemblyName System.Web
$firstPart = "https://duckduckgo.com/?q="
$lastPart = "&t=ffsb&ia=web"
$encodedTerms = [System.Web.HttpUtility]::UrlEncode($searchTerms)
$address = "{0}{1}{2}" -f $firstPart, $encodedTerms, $lastPart
start-process $address
}
function fn
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true)]
[double] $number
)
Process
{
"{0:n0}" -f $number
}
}
function mojeek ([string] $searchTerms)
{
Add-Type –AssemblyName System.Web
$firstPart = "https://www.mojeek.com/search?q="
$lastPart = ""
$encodedTerms = [System.Web.HttpUtility]::UrlEncode($searchTerms)
$address = "{0}{1}{2}" -f $firstPart, $encodedTerms, $lastPart
start-process $address
}
function ssv
{
param(
[ValidateRange(0,100)]
[Int]
$volume = 20
)
$wshShell = New-Object -ComObject wscript.shell
# Convert [Int] $volume to number of key presses.
$keyPressesTemp = $volume / 2
$keyPresses = [math]::ceiling($keyPressesTemp)
# Set volume to zero.
1..50 | % { $wshShell.SendKeys([char]174) }
# If $volume is zero.
if ($keyPresses -eq 0)
{
# do nothing
}
# If $volume is non-zero.
else
{
1..$keyPresses | % { $wshShell.SendKeys([char]175) }
}
}
function stamp ([string] $choice = "0")
{
switch ($choice)
{
"1" {
"$(get-date -format 'dddd, MMMM d, yyyy h:mm:ss tt')`n" | Set-Clipboard
}
"2" {
"`n`n$(get-date -format 'dddd, MMMM d, yyyy h:mm:ss tt')`n`n" | Set-Clipboard
}
"blog" {
"$(get-date -format 'dddd, MMMM d, yyyy')" | Set-Clipboard
}
default {
"$(get-date -format 'dddd, MMMM d, yyyy h:mm:ss tt')" | Set-Clipboard
}
}
}
function Start-Hourglass ([string] $myInput)
{
$myInput -match "^ *([\w ]+\w) +(\d{1,3}m)$" | out-null
$myCommand = "hourglass --title `"$($matches[1])`" $($matches[2])"
Invoke-Expression $mycommand
}
function Wait-Computer
{
Add-Type -AssemblyName System.Windows.Forms
$powerState = [Windows.Forms.PowerState]::Suspend
[Windows.Forms.Application]::SetSuspendState($powerState, $false, $false) | Out-Null
}
function washingmachine { & "C:\Program Files (x86)\Hourglass\Hourglass.exe" --title "Washing Machine" "35m" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment