Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 正在尝试根据修改的日期排列文件_Powershell - Fatal编程技术网

Powershell 正在尝试根据修改的日期排列文件

Powershell 正在尝试根据修改的日期排列文件,powershell,Powershell,我试图根据修改日期将PST文件加载到子文件夹中 例如,我想将日期修改为“24/09/2019”的PST文件移动到新创建的名为“24/09/2019”的文件夹中,该文件夹的名称基于修改的日期 我已设法根据一个文件创建了一个带日期的文件夹,但将该文件移动到该文件夹中并在多个文件上完成此过程不起作用 $LastModifiedDate = Get-ChildItem "C:\users\user\Desktop\Test\" $LastModified = $LastModifiedDate.Last

我试图根据修改日期将PST文件加载到子文件夹中

例如,我想将日期修改为“24/09/2019”的PST文件移动到新创建的名为“24/09/2019”的文件夹中,该文件夹的名称基于修改的日期

我已设法根据一个文件创建了一个带日期的文件夹,但将该文件移动到该文件夹中并在多个文件上完成此过程不起作用

$LastModifiedDate = Get-ChildItem "C:\users\user\Desktop\Test\"
$LastModified = $LastModifiedDate.LastWriteTime.ToString("dd-MM-yyyy")

$LastModifiedDate | ForEach-Object  {
    New-Item -ItemType directory -Path "C:\users\user\desktop\Test\" -Name $LastModified
    Move-Item $LastModifiedDate -Path "C:\users\user\desktop\test\$LastModified"
}

echo $LastModifiedDate
echo $LastModified

假设您的PST文件都位于您指定的路径中,您可以使用以下内容:

$BasePath = 'C:\users\user\Desktop\Test'
Get-ChildItem -Path $BasePath -Filter *.pst |
    ForEach-Object {
        $Date = Get-Date $_.LastWriteTime -Format 'yyyyMMdd'
        $TargetPath = Join-Path -Path $BasePath -ChildPath $Date
        If (-not (Test-Path -Path $TargetPath)) {
            New-Item -Path $TargetPath -ItemType Directory -Force
        }
        Move-Item -Path $_.FullName -Destination $TargetPath
    }

你我的朋友是个英雄,这真是个好机会!多谢各位