更改父文件夹的创建日期以及所有子对象

时间:2014-08-10 18:53:24

标签: powershell

我正在运行一个脚本来更改文件/文件夹的创建日期,但是虽然它更改了文件夹中的文件夹和文件,但它不会更改实际父文件夹的日期。脚本在下面,任何人都可以建议需要改变什么。

# Get the files
$gFiles = Get-ChildItem -recurse G:\
# Loop through them all
$gFiles | ForEach-Object {
    # Set the creation date without returning any output
    ($_.CreationTime = '10/08/2014 1:00') |Out-Null
    # Test if the previous operation was successful:
    if($?)
    {
        # Success, create an object containing the Path and status
        New-Object PSObject -Property @{
            "FilePath" = $_.FullName
            "Result"   = "Success"
        }
    }
    else
     {
        # Success, create an object containing the Path and status
        New-Object PSObject -Property @{
            "FilePath" = $_.FullName
            "Result"   = "Failed"
        }
    }
# Export the objects containing the result to a .CSV file
} |Export-Csv -LiteralPath "C:\pslog.csv" -Delimiter ";" -NoTypeInformation -Force

1 个答案:

答案 0 :(得分:1)

您需要包含Get-ChildItem仅枚举子文件系统。

像这样 -

$gFiles = (Get-ChildItem -recurse G:\) + (Get-Item G:\)