微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我应该编写什么脚本以及在哪里定义:

> 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:\Windows\System32> Get-ExecutionPolicy
Restricted
PS C:\Windows\System32>

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

PS C:\Windows\System32> Set-Executionpolicy RemoteSigned -Scope CurrentUser

原文地址:https://www.jb51.cc/windows/365237.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐