2012-08-27 24 views
5

kịch bản gì và ở đâu tôi nên viết để xác định:cấu hình PowerShell với một file rc-như

  1. alias for ll="ls -l"
  2. alias/function cd = "original cd; ll"

Vì vậy, câu hỏi của tôi có đến các bộ phận mà là tệp rc của Power Shell trên Windows 7 và cách bí danh ll đến ls -lcd đến cd; ll?

Trả lời

7

Tạo tệp ở vị trí vỏ nguồn trỏ đến khi bạn nhập $profile và nhấn enter, nếu nó không tồn tại. (Để biết thêm thông trông here.)

Ngoài ra tôi đã tìm thấy một rất nhiều ví dụ tốt bên cạnh powershell.exe trong hệ thống của tôi có một thư mục ví dụ, nơi có một file có tên profile.ps1 với đoạn mã sau:

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 
    } 
} 

Cũng tính đến vấn đề sau. Bạn có thể gặp lỗi sau trong khi thực thi tệp nằm trong $profile:

Microsoft.PowerShell_profile.ps1 không thể tải được vì việc thực thi tập lệnh bị tắt trên hệ thống này. Vui lòng xem get-help about_signing để biết thêm chi tiết.

Giải pháp: Kiểm tra dòng điện thực hiện chính sách

PS C:\Windows\System32> Get-ExecutionPolicy 
Restricted 
PS C:\Windows\System32> 

Để thay đổi việc sử dụng thực hiện chính sách hiện tại: Lưu ý: lệnh này phải được chạy nâng (Bắt đầu Powershell sử dụng 'Run as Administrator')

PS C:\Windows\System32> Set-Executionpolicy -ExecutionPolicy Unrestricted 
Các vấn đề liên quan