1. powershell 用安装包安装,它会配置些环境变量
2. include 多文件
$ownSscriptRoot = 'abs:\path\to\PowerShell\'
$workPS = $ownSscriptRoot + "work.ps1"
3. location
配置全局的
C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1
4. 例
$ownSscriptRoot = 'abs:\path\to\PowerShell\'
$workPS = $ownSscriptRoot + "work.ps1"
Import-Module $workPS
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
function Get-GitSStatus { & git status }
New-Alias -Name gs -Value Get-GitSStatus -Force -Option AllScope
function Get-GitGraph { & git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim white)%aD%C(reset) %C(dim white)(%ar) %C(dim white)- %an%C(reset) %C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset)' --all }
New-Alias -Name gg -Value Get-GitGraph -Force -Option AllScope
function Get-GitGraphC { & git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim white)%aD%C(reset) %C(dim white)(%ar) %C(dim white)- %an%C(reset) %C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset)' --all -c }
New-Alias -Name ggc -Value Get-GitGraphC -Force -Option AllScope
function Get-GitGraphS { & git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(dim white)%aD%C(reset) %C(dim white)(%ar) %C(dim white)- %an%C(reset) %C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset)' --all --stat }
New-Alias -Name ggs -Value Get-GitGraphS -Force -Option AllScope
function StartVS64Console { & cmd /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" }
New-Alias -Name vsc -Value StartVS64Console -Force -Option AllScope
function getIPV4Addr {(Get-NetIPConfiguration | Where-Object {$_.IPv4DefaultGateway -ne $null -and $_.NetAdapter.status -ne "Disconnected"}).IPv4Address.IPAddress}
New-Alias -Name ipv4a -Value getIPV4Addr
function Run-gitCheck { & git checkout }
New-Alias -Name gitck -Value Run-gitCheck -Force -Option AllScope
function Run-gitBranch { & git branch }
New-Alias -Name gitbr -Value Run-gitBranch -Force -Option AllScope
function Start-HibernationS
{
rundll32.exe PowrProf.dll, SetSuspendState 0,1,0
}
New-Alias -Name ph -Value Start-HibernationS -Force -Option AllScope
New-Alias -Name vbm -Value vboxmanage -Force -Option AllScope
<#
.SYNOPSIS
Modify the PATH environment variable.
.DESCRIPTION
Set-PathVariable allows you to add or remove paths to your PATH variable at the specified scope with logic that prevents duplicates.
.PARAMETER AddPath
A path that you wish to add. Can be specified with or without a trailing slash.
.PARAMETER RemovePath
A path that you wish to remove. Can be specified with or without a trailing slash.
.PARAMETER Scope
The scope of the variable to edit. Either Process, User, or Machine.
If you specify Machine, you must be running as administrator.
.EXAMPLE
Set-PathVariable -AddPath C:\tmp\bin -RemovePath C:\path\java
This will add the C:\tmp\bin path and remove the C:\path\java path. The Scope will be set to Process, which is the default.
Set-PathVariable -AddPath "C:\tmp abc\bin" -Scope Machine
Set-PathVariable -RemovePath C:\tmp\bin -Scope Machine
Set-PathVariable -RemovePath "C:\tmp abc\bin" -Scope Machine
.INPUTS
.OUTPUTS
.NOTES
Author: ThePoShWolf
.LINK
#>
Function Set-PathVariable {
param (
[string]$AddPath,
[string]$RemovePath,
[ValidateSet('Process', 'User', 'Machine')]
[string]$Scope = 'Process'
)
$regexPaths = @()
if ($PSBoundParameters.Keys -contains 'AddPath') {
$regexPaths += [regex]::Escape($AddPath)
}
if ($PSBoundParameters.Keys -contains 'RemovePath') {
$regexPaths += [regex]::Escape($RemovePath)
}
$arrPath = [System.Environment]::GetEnvironmentVariable('PATH', $Scope) -split ';'
foreach ($path in $regexPaths) {
$arrPath = $arrPath | Where-Object { $_ -notMatch "^$path\\?" }
}
$value = ($arrPath + $addPath) -join ';'
[System.Environment]::SetEnvironmentVariable('PATH', $value, $Scope)
}
Function Get-ENV {
# gci env:* | select Name,Value
# Get-ChildItem Env:* | Select-Object -Property Name,Value
# [System.EnvironmentVariableTarget]::Machine
# [System.EnvironmentVariableTarget]::User
# [System.EnvironmentVariableTarget]::Process
# Get-ChildItem env: | Format-List
echo ""
echo "Begin ENV: =================================================================================================================="
echo ""
echo "Process ENV Begin : ------------------------------------------------------------------------------------------------------------"
[System.Environment]::GetEnvironmentVariables('Process') | Format-List
echo "Process ENV End : ------------------------------------------------------------------------------------------------------------"
echo ""
echo "User ENV Begin : ------------------------------------------------------------------------------------------------------------"
[System.Environment]::GetEnvironmentVariables('User') | Format-List
echo "User ENV End : ------------------------------------------------------------------------------------------------------------"
echo ""
echo "Machine ENV Begin : ------------------------------------------------------------------------------------------------------------"
[System.Environment]::GetEnvironmentVariables('Machine') | Format-List
echo "Machine ENV End : ------------------------------------------------------------------------------------------------------------"
echo ""
echo "End ENV: =================================================================================================================="
echo ""
}