我是PowerShell的新手,我只想弄清楚它是如何工作的.
那么,我该如何编写这段代码:
Get-ChildItem C:\ | Sort-Object Length
Run Code Online (Sandbox Code Playgroud)
作为多行代码?我试过这个:
$child_items = Get-ChildItem C:\
Sort-Object $child_items Length
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我越来越:
Sort-Object : A positional parameter cannot be found that accepts argument 'Length'.
Run Code Online (Sandbox Code Playgroud)
虽然其他答案是使用命名参数传递值的正确方法,但请记住get-help Sort-Object:
When you use the InputObject parameter to submit a collection of items,
Sort-Object receives one object that represents the collection.
Because one object cannot be sorted, Sort-Object returns the entire collection unchanged.
Run Code Online (Sandbox Code Playgroud)
你会发现没有将$ child_items传递给的排序操作-inputobject.
您始终需要使用管道传递值 -inputobject
| 归档时间: |
|
| 查看次数: |
714 次 |
| 最近记录: |