2019-10-21 19:37:23 -05:00
|
|
|
# My powershell profile.
|
|
|
|
|
|
|
|
# customize the prompt to be a little more useful
|
|
|
|
function prompt {
|
|
|
|
Write-Host -NoNewLine "["
|
|
|
|
Write-Host -NoNewLine -Fore Green ("{0:HH}:{0:mm}" -f $(get-date))
|
|
|
|
Write-Host -NoNewLine "] "
|
|
|
|
Write-Host -Fore Cyan "${pwd}"
|
|
|
|
"PS> "
|
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Invoke a scriptblock with evelvated permissions.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function Invoke-Elevated {
|
2021-10-28 21:51:17 -04:00
|
|
|
param (
|
|
|
|
[ScriptBlock]
|
|
|
|
$code
|
|
|
|
)
|
|
|
|
$outTmpFile = [System.IO.Path]::GetTempFileName()
|
|
|
|
$errTmpFile = [System.IO.Path]::GetTempFileName()
|
2020-02-09 07:44:46 -06:00
|
|
|
|
2021-10-28 21:51:17 -04:00
|
|
|
$code | Write-Output
|
|
|
|
$outTmpFile | Write-Output
|
|
|
|
$errTmpFile | Write-Output
|
|
|
|
# TODO(jwall): Work on figuring out how to properly redirect output here
|
|
|
|
Start-Process powershell.exe -ArgumentList { &$code 1>$outTmpFile 2>$errTmpFile } -WindowStyle hidden -Verb RunAs
|
|
|
|
Get-Content $outTmpFile | Write-Output
|
|
|
|
Get-Content $errTmpFile | Write-Output
|
|
|
|
Remove-Item $outTmpFile
|
|
|
|
Remove-Item $errTmpFile
|
2019-10-21 19:37:23 -05:00
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Returns true if you are running with elevated privileges.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function Get-Elevated {
|
|
|
|
([Security.Principal.WindowsPrincipal] `
|
2021-10-28 21:51:17 -04:00
|
|
|
[Security.Principal.WindowsIdentity]::GetCurrent() `
|
2019-10-21 19:37:23 -05:00
|
|
|
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
|
|
}
|
|
|
|
|
2019-10-21 20:18:43 -05:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Create a symlink from a source to a destination.
|
|
|
|
|
|
|
|
.Description
|
|
|
|
Creates a symlink from a $Source to a $Destination.
|
|
|
|
Automatically elevates to administrator privileges
|
|
|
|
if necessary.
|
|
|
|
|
|
|
|
.Parameter Source
|
|
|
|
Required source to create the symlink from.
|
|
|
|
|
|
|
|
.Parameter Destination
|
|
|
|
Required destination to create the symlink at.
|
|
|
|
#>
|
2019-10-21 19:37:23 -05:00
|
|
|
function New-Link {
|
|
|
|
param (
|
2021-10-28 21:51:17 -04:00
|
|
|
[Parameter(Position = 0, Mandatory = $true)]
|
2020-02-09 07:44:46 -06:00
|
|
|
[string[]]
|
2019-10-21 19:37:23 -05:00
|
|
|
$Source,
|
|
|
|
|
2021-10-28 21:51:17 -04:00
|
|
|
[Parameter(Position = 1, Mandatory = $true)]
|
2020-02-09 07:44:46 -06:00
|
|
|
[string[]]
|
2019-10-21 19:37:23 -05:00
|
|
|
$Destination
|
|
|
|
)
|
|
|
|
|
|
|
|
# This is a bit of a hack but it's necessary until they make it possible
|
|
|
|
# to do symbolic links without administrator privileges
|
|
|
|
if (Get-Elevated) {
|
|
|
|
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
|
2021-10-28 21:51:17 -04:00
|
|
|
}
|
|
|
|
else {
|
2019-10-21 19:37:23 -05:00
|
|
|
# Elevate our permissions for this first.
|
|
|
|
Invoke-Elevated {
|
|
|
|
New-Item -ItemType SymbolicLink -Path $Destination -Target $Source
|
|
|
|
}
|
|
|
|
}
|
2019-10-26 14:59:31 -05:00
|
|
|
}
|
|
|
|
|
2021-10-28 21:51:17 -04:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Get Powershell Version and optionally the host version.
|
|
|
|
|
|
|
|
.Parameter Full
|
|
|
|
Show all the version information not just the version
|
|
|
|
number and edition.
|
|
|
|
|
|
|
|
.Parameter WithHost
|
|
|
|
Show the Host version as well.
|
|
|
|
#>
|
|
|
|
function Get-PSVersion {
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[Switch] $Full,
|
|
|
|
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[Switch] $WithHost
|
|
|
|
)
|
|
|
|
|
|
|
|
if ($Full) {
|
|
|
|
$PSVersionTable |
|
|
|
|
if ($WithHost) {
|
|
|
|
Get-Host
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
@{ PSVersion = $PSVersionTable.PSVersion; PSEdition = $PSVersionTable.PSEdition }
|
|
|
|
if ($WithHost) {
|
|
|
|
$HostInfo = Get-Host
|
|
|
|
@{HostName = $HostInfo.Name; HostVersion = $HostInfo.Version }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $output
|
|
|
|
}
|
|
|
|
|
|
|
|
function Get-Base64-Decoded {
|
|
|
|
[CmdletBinding()]
|
|
|
|
param (
|
|
|
|
[Parameter()]
|
|
|
|
[string[]]
|
|
|
|
$encoded
|
|
|
|
)
|
|
|
|
[Text.Encoding]::Utf8.GetString([Convert]::FromBase64String($encoded))
|
|
|
|
}
|
|
|
|
|
2020-02-09 07:44:46 -06:00
|
|
|
function grep {
|
2021-10-28 21:51:17 -04:00
|
|
|
$input | out-string -stream | select-string $args
|
2020-02-09 07:44:46 -06:00
|
|
|
}
|
|
|
|
|
2019-10-26 14:59:31 -05:00
|
|
|
# It's way more useful to call this open than ii
|
2019-11-09 19:52:12 -06:00
|
|
|
Set-Alias -Name open -Value Invoke-Item
|
2020-02-09 07:44:46 -06:00
|
|
|
Set-Alias -Name ln -Value New-Link
|
2020-06-17 17:34:07 -05:00
|
|
|
Set-Alias -name which -Value Get-Command
|
|
|
|
|
2019-11-09 19:52:12 -06:00
|
|
|
# Add make to our powershell path
|
2021-10-28 21:51:17 -04:00
|
|
|
$env:PATH = "$env:PATH;C:\Program Files (x86)\GnuWin32\bin;C:\Users\jerem\AppData\Local\Julia-1.3.0\bin;C:\Users\jerem\AppData\Roaming\nvm;C:\Users\jerem\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin"
|
|
|
|
$env:NVM_HOME = "C:\Users\jerem\AppData\Roaming\nvm"
|