【问题标题】:Listing files in recycle bin from another computer从另一台计算机列出回收站中的文件
【发布时间】:2019-10-15 08:07:27
【问题描述】:

我正在使用此 PowerShell 代码获取一个 txt 文件,其中包含回收站中的所有文件及其原始位置(来自 Listing files in recycle bin):

(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 启动此 .ps1 文件,以获取计算机 B 的回收站中的文件(例如 \172.00.00.00),进入 \172.00.00.00\folder 并启动 cmd启动该 .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的回收站?

谢谢!

【问题讨论】:

标签: powershell recycle-bin


【解决方案1】:

将您的代码包装成一个简单的迷你函数,并在远程传递计算机名和系统凭据中调用它。如果您使用的是企业管理员,那么您无需通过凭据,它将使用您的 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。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多