繁体   English   中英

从另一台计算机列出回收站中的文件

[英]Listing files in recycle bin from another computer

我正在使用这个 PowerShell 代码来获取一个 txt 文件,其中包含回收站中的所有文件及其原始位置(从回收站中的列表文件中获得):

(New-Object -ComObject Shell.Application).NameSpace(0x0a).Items()|select @{n="OriginalLocation";e={$_.ExtendedProperty("{9B174B33-40FF-11D2-A27E-00C04FC30871} 2")}},Name| export-csv -delimiter "\" -path C:\Desktop\file_list_$(get-date -f yyyyMMdd).txt -NoTypeInformation

(gc C:\Desktop\file_list_$(get-date -f yyyyMMdd).txt | select -Skip 1)| % {$_.Replace('"','')}| set-content C:\Desktop\file_list_$(get-date -f yyyyMMdd).txt

而且效果很好。 现在的问题是,我被要求从计算机 A 启动 this.ps1 文件以获取计算机 B 的回收站中的文件(例如 \172.00.00.00),进入 \172.00.00.00\folder 并启动 cmd启动 that.ps1 文件的文件。

我已经设置

(New-Object -ComObject Shell.Application).NameSpace(0x0a).Items()|select @{n="OriginalLocation";e={$_.ExtendedProperty("{9B174B33-40FF-11D2-A27E-00C04FC30871} 2")}},Name| export-csv -delimiter "\" -path \\172.00.00.00\C\Desktop\file_list_$(get-date -f yyyyMMdd).txt -NoTypeInformation

(gc \\172.00.00.00\C\Desktop\file_list_$(get-date -f yyyyMMdd).txt | select -Skip 1)| % {$_.Replace('"','')}| set-content \\172.00.00.00\C\Desktop\file_list_$(get-date -f yyyyMMdd).txt

但是我如何告诉它检查计算机B的回收站?

谢谢!

将您的代码包装成一个简单的迷你 function 并在远程传递计算机名和系统凭据中调用它。 如果您使用的是企业管理员,那么您无需通过凭据,它将使用您的 windows 身份验证连接到远程系统。

$scriptblock = {
    function Get-RecycleBinItems 
    {
        (New-Object -ComObject Shell.Application).NameSpace(0x0a).Items() |
            Select-Object Name, Size, Path
    }
    Get-RecycleBinItems
}

Invoke-Command -ComputerName $computer -ScriptBlock $scriptblock 

要传递凭据,您可以使用:

Read-Host -assecurestring | convertfrom-securestring | out-file C:\path\username-password-encrypted.txt
$username = 'domain\username'
$password = 'password' | convertto-securestring
$creds = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Invoke-Command -ComputerName Hostname -ScriptBlock $ScriptBlock -Credential $creds

注意:我期望 PSRemoting 已配置。 如果未配置,请确保先配置 PSRemoting。

希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM