【问题标题】:Why does this work (or how)?为什么这样做(或如何)?
【发布时间】:2013-08-26 19:54:46
【问题描述】:

在我今天的电子邮件中,我收到了一封关于获取未使用的驱动器号的电子邮件。 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怎么没有显示?

【问题讨论】:

    标签: variables powershell dynamic


    【解决方案1】:

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

    所以,function:[d-z]: 列出了从“d:”到“z:”的函数

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

    【讨论】:

    • 谢谢。我从来没有意识到function: 是一个 PSDrive。现在我明白了,我觉得使用它还不错。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多