Get-ChildItem -Path "D:\GitRepository\test" -Recurse -Filter "*A*"
function testFunc($path,$pattern) {
Get-ChildItem -Path $path -Recurse -Filter $pattern
}
testFunc("D:\GitRepository\test","*A*")
感觉这两条命令应该有相同的效果,一个是直接调用 Cmdlet,另一个是通过函数调用.
但是结果不同,前者正常,后者则是将工作目录下的所有成员列出了.
肯定是我有地方理解错了,但是想了很长时间也没搞清楚,所以寻求帮助.
前者:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2020/10/20 15:32 611 AAA.cfg
后者:
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2020/10/20 15:32 611 AAA.cfg
-a--- 2020/10/20 15:32 611 BBB.cfg
-a--- 2020/10/20 15:32 611 CCC.cfg
-a--- 2020/10/20 15:42 218 test.ps1
Directory: D:\GitRepository\PowerShell\example
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2020/10/20 11:34 class
Directory: D:\GitRepository\PowerShell\example\class
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2020/10/14 21:08 850 example-static.ps1
-a--- 2020/10/16 11:25 694 learn-example-static.ps1
Directory: D:\GitRepository\PowerShell\example
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2020/10/20 11:34 hash-table
Directory: D:\GitRepository\PowerShell\example\hash-table
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2020/10/15 11:23 267 hash-table.ps1
-a--- 2020/10/15 11:22 258 hash-table-cannot-self-reference.ps1
... ... ...
1
AndyAO OP 懂了,PowerShell 这奇葩语法也是扶它了.
|