簡體   English   中英

如何使用 Powershell 腳本在遠程計算機上查找 PST 文件

[英]How to find PST files on remote computers using Powershell script

我需要一些幫助。 我找不到我的 PowerShell 腳本有什么問題。

目標很簡單。 我必須在網絡中域計算機上的用戶配置文件中找到 (.*pst) 文件。
要搜索的位置是“C:\Users\”。 導出到 listcomputer.txt 的 PC 名稱列表。
問題是腳本運行時沒有錯誤也沒有任何消息

$computers = Get-Content c:\temp\listcomputer.txt
$filePath = "C:\Users\" 
foreach($computer in $computers)
    {
    if(Test-Connection -ComputerName $computer -Quiet) 
{
Invoke-Command -ComputerName $computer -ScriptBlock 
{Get-ChildItem -Path $filePath -Recurse -Include '*.pst, *.ost'} }}


首先,我必須通過Test-Connection cmdlet 檢查與主機的連接。

分別成功運行每個命令。 我試過了。
例如: Test-Connection -ComputerName $computer運行結果為“true”,沒關系。

Invoke-Command -ComputerName $computer -ScriptBlock {Get-ChildItem -Path $filePath -Recurse -Include '*.pst'}
結果顯示包含在文件夾中找到的文件信息的數據。
但所有這些都在 PowerShell 控制台中運行,沒有可見的結果
控制台查看結果

問候!

.pst可以位於任何地方,甚至是其他驅動器或附加存儲。 您只是在尋找C:\

所以也許這個重構會影響所有潛在的連接驅動器。:

Get-Content -Path 'c:\temp\listcomputer.txt' | 
ForEach-Object { 
    if(Test-Connection -ComputerName $PSItem -Quiet)
    {
        Invoke-Command -ComputerName $PSItem -ScriptBlock {
            (Get-CimInstance -ClassName Win32_LogicalDisk).DeviceID | 
            ForEach-Object {
                If ($PSItem -eq 'C:')
                {Get-ChildItem -Path "$PSItem\Users" -Recurse -Include '*.pst, *.ost'}
                Else {Get-ChildItem -Path $PSItem -Recurse -Include '*.pst, *.ost'}
            }
        } 
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM