Powershell - 变量数组 - 查找文件夹然后查找文件夹中的文件
Powershell - Variables Array's - Finding Folders then Files in Folder
我真的需要 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 }
或者只是将路径导出到文本文件并导入到命令中?完全卡住了。
你的第一次尝试应该更像这样:
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 }
我真的需要 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 }
或者只是将路径导出到文本文件并导入到命令中?完全卡住了。
你的第一次尝试应该更像这样:
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 }