apiv1

改配置文件法(已经有配置文件的情况)

vim $PROFILE.CurrentUserAllHosts

贴入

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

管理员shell执行

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

一步到位法(自动写配置文件)

复制到管理员终端直接执行

ni -Type File -Path $PROFILE
sc -Path $PROFILE -Value '
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
'
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

步骤解释

创建PS的Profile文件 如果没有使用过PS相关的功能,Profile文件应该是没有的。下面是创建命令

ni是New-Item的缩写

$PROFILE是系统提供的PROFILE地址

ni -Type File -Path $PROFILE 写入命令 打开Profile文件写入下列命令

Set-PSReadLineOption -HistorySearchCursorMovesToEnd Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward 脚本权限控制 一般默认的用户权限是Undefined,是没有办法执行脚本文件的。

我们需要通过设置更高的权限来运行我们的脚本。

通过该命令查看我们当前用户(CurrentUser)的权限

Get-ExecutionPolicy -List

通过该命令设置当前用户的权限

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 这是权限相关的文档。 https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies

最后 重启PowerShell窗口,或者打开新的。