Powershell - 变量数组 - 查找文件夹然后文件夹中的文件

时间:2015-02-10 16:48:00

标签: arrays variables powershell

我真的需要Powershell的帮助,Powershell中的新手

我有下面的命令,它输出一个路径列表,搜索在共享上多次创建的名为“xyz”的文件夹,用作变量

$FOLDERLISTS = (Get-ChildItem \\server\share -Recurse | Where-Object { ( $._PSIsContainer -eq $true) -and ($_.Name -like "xyz" -and ( $_.mode -match "d") | % { Write-Host $_.FullName })

如何使用多个文件夹路径,我可以将其设置为变量吗?

基本上我只想获取文件夹路径,然后针对上面命令输出的每个文件夹路径运行另一个Get-ChildItem,所以如果它是单个变量,那么命令看起来就像;

Get-ChildItem "@ABOVECOMMAND" -Recurse | Where-Object ( !($_.PSIsContainer) -and $_.lenght -le 1000000 )

我可以以某种方式使用ForEach来运行多条路径吗?

foreach ($FOLDERLIST in $FOLDERLISTS)
{
Get-ChildItem -Recurse | Where-Object { !($_.PSIsContainer) -and $_.lenght -le 1000000 }
}

或者

$FOLDERLISTS | ForEach-Object{
Get-ChildItem -Recurse | Where-Object { !($_.PSIsContainer) -and $_.lenght -le 1000000 }

或者只是将路径导出到文本文件并导入命令?完全卡住了。

1 个答案:

答案 0 :(得分:1)

你的第一次尝试应该更像这样:

foreach ($FOLDERLIST in $FOLDERLISTS)
{
Get-ChildItem $FOLDERLIST -Recurse | Where-Object { !($_.PSIsContainer) -and $_.lenght -le 1000000 }
}

或者你的第二次尝试是这样的:

$FOLDERLISTS | ForEach-Object{
Get-ChildItem $_ -Recurse | Where-Object { !($_.PSIsContainer) -and $_.lenght -le 1000000 }
相关问题