PowerShell获取文件夹的已删除文件

时间:2018-08-27 01:24:49

标签: powershell powershell-v4.0 recycle-bin

我尝试使用Get-ChildItem和Trash获取文件夹的已删除文件,但效果不佳。在垃圾桶中,我可以获取文件,但是我不知道如何发现执行脚本的文件夹中的文件。

class PostPolicy
  attr_reader :user, :post

  def initialize(user, post)
    @post = post
    @user = user
  end

  def index?
    true
  end

  def show?
    true
  end

  def create?
    user.admin? || @post.user == user
  end

  def create?
    user.admin? || @post.user == user
  end

  def destroy?
    user.admin? || @post.user == user
  end

end

1 个答案:

答案 0 :(得分:4)

NameSpace method返回一个Folder object,其中提供了一个GetDetailsOf method,您可以使用它来检索有关member中每个Items的详细信息:

New-Variable -Name 'ssfBITBUCKET'                       -Option Constant -Value 0x0A;
New-Variable -Name 'BitBucketDetails_Name'              -Option Constant -Value 0;
New-Variable -Name 'BitBucketDetails_ParentPath'        -Option Constant -Value 1;
New-Variable -Name 'BitBucketDetails_DeletionTimeText'  -Option Constant -Value 2;
New-Variable -Name 'BitBucketDetails_SizeText'          -Option Constant -Value 3;
New-Variable -Name 'BitBucketDetails_Type'              -Option Constant -Value 4;
New-Variable -Name 'BitBucketDetails_LastWriteTimeText' -Option Constant -Value 5;
New-Variable -Name 'BitBucketDetails_CreationTimeText'  -Option Constant -Value 6;
New-Variable -Name 'BitBucketDetails_LastAccessTimeText'-Option Constant -Value 7;
New-Variable -Name 'BitBucketDetails_AttributesText'    -Option Constant -Value 8;

$application = New-Object -ComObject 'Shell.Application';
$bitBucket = $application.NameSpace($ssfBITBUCKET);

foreach ($deletedItem in $bitBucket.Items())
{
    New-Object -TypeName 'PSObject' -Property @{
        # Same as $deletedItem.Name
        Name =               $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_Name);
        ParentPath =         $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_ParentPath);
        DeletionTimeText =   $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_DeletionTimeText);
        Size =               $deletedItem.Size;
        SizeText =           $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_SizeText);
        # Same as $deletedItem.Type
        Type =               $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_Type);
        LastWriteTime =      $deletedItem.ModifyDate;
        LastWriteTimeText =  $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_LastWriteTimeText);
        CreationTimeText =   $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_CreationTimeText);
        LastAccessTimeText = $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_LastAccessTimeText);
        AttributesText =     $bitBucket.GetDetailsOf($deletedItem, $BitBucketDetails_AttributesText);
        IsFolder =           $deletedItem.IsFolder();
        BitBucketPath =      $deletedItem.Path;
    };
}

ssfBITBUCKET来自ShellSpecialFolderConstants enumeration。在设置为en-US的Windows 10系统上,将BitBucketDetails_*TimeText常量传递给GetDetailsOf()时,它不返回DateTime实例,而是返回{ {1}},其中年,月和日分别以left-to-right mark ([Char] 0x200E)开头,而时间以right-to-left mark ([Char] 0x200F)开头,并带有从左到右的标记。

我自己确定了String常数,因为我没有在任何地方记录它们,但是根据this answer,您可以通过将BitBucketDetails_*作为第一个参数传递给{{ 1}}。因此,您可以继续从位存储桶命名空间中查询列名称,直到它开始返回空的$null为止……

GetDetailsOf()

...这会在我的系统上输出...

String