从Switch / Get-Content中获取filename / PSChildName

时间:2013-07-16 14:35:41

标签: powershell

我有以下代码,我不知道如何从案例块中访问文件名。

Switch -regex (Get-Content -Path C:\Users\Ryan\Desktop\ps-temp\*) {
  '\.DEBUG' {
     # How to access filename/PSChildName here?
  }
}

1 个答案:

答案 0 :(得分:3)

我不确定你能不能。 $_在大括号内可用,但它引用了匹配的字符串。请尝试使用Select-String cmdlet:

Get-ChildItem C:\Users\Ryan\Desktop\ps-temp\* | Select-String '\.DEBUG'