加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

具有类似rc的文件的PowerShell配置

发布时间:2020-12-14 04:07:57 所属栏目:Windows 来源:网络整理
导读:我应该编写什么脚本以及在哪里定义: ll =“ls -l”的别名 alias / function cd =“original cd; ll” 所以,我的问题是如何将Windows 7上的Power Shell的rc文件放在哪里以及如何将ll别名为ls -l和cd为cd;二? 在键入$profile时,在power shell指向的位置创建
我应该编写什么脚本以及在哪里定义:

> ll =“ls -l”的别名
> alias / function cd =“original cd; ll”

所以,我的问题是如何将Windows 7上的Power Shell的rc文件放在哪里以及如何将ll别名为ls -l和cd为cd;二?

在键入$profile时,在power shell指向的位置创建一个文件,如果不存在则按Enter键. (欲了解更多信息,请查看 here.)

另外我在我的系统中的powershell.exe旁边找到了很多很好的例子,有一个示例文件夹,其中有一个名为profile.ps1的文件,代码如下:

set-alias cat        get-content
set-alias cd         set-location
set-alias clear      clear-host
set-alias cp         copy-item
set-alias h          get-history
set-alias history    get-history
set-alias kill       stop-process
set-alias lp         out-printer
set-alias ls         get-childitem
set-alias mount      new-mshdrive
set-alias mv         move-item
set-alias popd       pop-location
set-alias ps         get-process
set-alias pushd      push-location
set-alias pwd        get-location
set-alias r          invoke-history
set-alias rm         remove-item
set-alias rmdir      remove-item
set-alias echo       write-output

set-alias cls        clear-host
set-alias chdir      set-location
set-alias copy       copy-item
set-alias del        remove-item
set-alias dir        get-childitem
set-alias erase      remove-item
set-alias move       move-item
set-alias rd         remove-item
set-alias ren        rename-item
set-alias set        set-variable
set-alias type       get-content

function help
{
    get-help $args[0] | out-host -paging
}

function man
{
    get-help $args[0] | out-host -paging
}

function mkdir
{
    new-item -type directory -path $args
}

function md
{
    new-item -type directory -path $args
}

function prompt
{
    "PS " + $(get-location) + "> "
}

& {
    for ($i = 0; $i -lt 26; $i++) 
    { 
        $funcname = ([System.Char]($i+65)) + ':'
        $str = "function global:$funcname { set-location $funcname } " 
        invoke-expression $str 
    }
}

还要考虑到以下问题.执行位于$profile中的文件时,您可能会遇到以下错误:

“Microsoft.PowerShell_profile.ps” cannot be loaded because the execution of scripts is disabled on this system. Please see “get-help about_signing” for more details.

解:
检查当前的执行策略

PS C:WindowsSystem32> Get-ExecutionPolicy
Restricted
PS C:WindowsSystem32>

要更改执行策略以允许PowerShell从本地文件执行脚本,请运行以下命令:

PS C:WindowsSystem32> Set-Executionpolicy RemoteSigned -Scope CurrentUser

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读