首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Get-ChildItem中的Get-ChildItem

Get-ChildItem中的Get-ChildItem
EN

Stack Overflow用户
提问于 2021-06-09 10:44:21
回答 2查看 46关注 0票数 1

我有一个关于我正在写的脚本的问题。我需要一个脚本,它可以查找特定文件夹(在本例中为WRA)中的所有文件夹,但我还希望查找WRA中的子文件夹,例如:\Server01\WRA包含100个文件夹\Server01\WRA\Folder1\Server01\WRA\Folder2...

我想查看“文件夹1”的内部,并获得“文件夹1”内的文件夹的报告,并找到超过30天的文件夹,这可以完成

代码语言:javascript
复制
Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-30))}

这是我到目前为止所拥有的

代码语言:javascript
复制
$FolderNames = Get-ChildItem "\\Server01\WRA\" -Directory | 
    Select-Object Name, LastWriteTime

$FolderNames

谢谢你的帮助

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-09 10:58:47

您可以使用以下命令:

代码语言:javascript
复制
Get-ChildItem "\\Server01\WRA\" -Directory |
Get-ChildItem -Directory |
Where-Object -Property LastWriteTime -LT ([datetime]::Now).AddDays(-30) |
Select-Object Name, LastWriteTime

编辑

代码语言:javascript
复制
$directories = Get-ChildItem "\\Server01\WRA\" -Directory
$targetDate = ([datetime]::Now).AddDays(-30)

foreach($parentDir in $directories)
{
    $subFolders = Get-ChildItem $parentDir -Directory |
    Where-Object -Property LastWriteTime -LT $targetDate
    
    if($subFolders)
    {
        "Parent Directory: {0}" -f $parentDir.FullName
    }

    foreach($childDir in $subFolders)
    {
        "Parent SubFolder: {0}" -f $childDir.FullName

        $childDir | Select-Object Name, LastWriteTime | Out-String
    }
}
票数 1
EN

Stack Overflow用户

发布于 2021-06-09 22:02:53

非常感谢你搭乘圣地亚哥的直升机!

我使用了您编写的脚本,但出现了以下错误:

代码语言:javascript
复制
Get-ChildItem : Cannot find path 'C:\Users\cubam1\Lonna' because it does not exist.
At line:6 char:19
+     $subFolders = Get-ChildItem $parentDir -Directory |
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\cubam1\Lonna:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Get-ChildItem : Cannot find path 'C:\Users\cubam1\Miguel' because it does not exist.
At line:6 char:19
+     $subFolders = Get-ChildItem $parentDir -Directory |
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\cubam1\Miguel:String) [Get-ChildItem], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

它似乎没有抓取正确的路径,路径应该是\Server01\WRA,但由于某种原因,它试图在"C:\Users\Cubam1“中找到它们谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67896840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档