为什么这样(或如何)?

E.V*_*.L. 3 variables powershell dynamic

在今天的电子邮件中,我收到了一封关于获取未使用的驱动器号 这是他们的解决方案:

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

PowerShell杂志BrainTeaser有一个解决方案,同样的事情.

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

我不知道是怎么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

Mik*_*ard 7

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

因此,function:[d-z]:列出"d:"到"z:"的功能

function:[d-a]: 不起作用,因为,da不是一系列字母.