2013-08-23 36 views
3

在我今天的电子邮件中,我收到了一封关于获取未使用的驱动器号的电子邮件。 This was their solution为什么这个工作(或如何)?

Get-ChildItem function:[d-z]: -Name | Where-Object {-not (Test-Path -Path $_)} 

PowerShell Magazine BrainTeaser had this for a solution, same thing.

ls function:[d-z]: -n|?{!(test-path $_)}|random 

我不知道如何function:[d-z]:作品。我知道使用'd'到'z'之间的每个字符,但我不知道语法为什么起作用。

测试Get-ChildItem function:[d-a]: -Name给你一个错误说Get-ChildItem : Cannot retrieve the dynamic parameters for the cmdlet. The specified wildcard pattern is not valid:[d-a]:

所以是一个动态的参数?怎么没有出现Get-Help gci -full

回答

7

function:是一款PSDrive,它揭示了当前会话中定义的一组函数。 PowerShell为每个单字母驱动器创建一个函数,命名为字母后跟冒号。

所以,function:[d-z]:名单从功能上 “d:” 到 “z:”

function:[d-a]:不起作用,因为,d-a不是一个范围的字母。

+1

谢谢。我从来没有意识到'功能:'是PSDrive。现在我明白了,我感觉没关系使用它。 –