我已经开始与PowerShell“玩耍”,并试图让它“表现”。
一个我想要做的事情是自定义提示是“相似”到什么“$ M $ P $ _ $ + $ G”做MS-DOS:
快速这些做什么的简化:
字符|描述
$ m如果当前驱动器不是网络驱动器,则与当前驱动器号或空字符串关联的远程名称。
$ P电流驱动器和路径
$ _ ENTER-LINEFEED
$ +零个或多个加号(+),这取决于PUSHD目录堆栈的深度字符,一个字符的每个平推
$ G>(大于号)
所以最终的输出是一样的东西:
\\spma1fp1\JARAVJ$ H:\temp
++>
我已经能够在$M
和$_
功能(和一个漂亮的历史记录功能)添加到我的提示如下:
function prompt
{
## Get the history. Since the history may be either empty,
## a single item or an array, the @() syntax ensures
## that PowerShell treats it as an array
$history = @(get-history)
## If there are any items in the history, find out the
## Id of the final one.
## PowerShell defaults the $lastId variable to '0' if this
## code doesn't execute.
if($history.Count -gt 0)
{
$lastItem = $history[$history.Count - 1]
$lastId = $lastItem.Id
}
## The command that we're currently entering on the prompt
## will be next in the history. Because of that, we'll
## take the last history Id and add one to it.
$nextCommand = $lastId + 1
## Get the current location
$currentDirectory = get-location
## Set the Windows Title to the current location
$host.ui.RawUI.WindowTitle = "PS: " + $currentDirectory
## And create a prompt that shows the command number,
## and current location
"PS:$nextCommand $currentDirectory
>"
}
但剩下的就是没有的东西我已经成功地复制...
非常感谢您的提示,一定会来!
忘记乘以字符串。那里好抓。今天早上太多的VBScript。 :(。 – EBGreen 2008-10-01 15:33:03