Powershell 如何在远程pc上进行数据搜索';s

Powershell 如何在远程pc上进行数据搜索';s,powershell,psexec,Powershell,Psexec,我有一个剧本: get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp -recurse > collection.txt 在本地计算机上进行采集时,此功能非常有效。但是,我需要同时在多台计算机上运行相同的东西。所以我在BAT文件中尝试了这个: PSexec @list.txt -u UserID -

我有一个剧本:

get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp 
-recurse > collection.txt
在本地计算机上进行采集时,此功能非常有效。但是,我需要同时在多台计算机上运行相同的东西。所以我在BAT文件中尝试了这个:

PSexec @list.txt -u UserID -p Password PowerShell get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp 
-recurse > collection.txt 2>&1 pause
PSexec @list.txt -u UserID -p Password PowerShell -command $env:computername; get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp -recurse 2>&1 > collection.txt
这在一些远程PC上有效,但我遇到了几个问题:

1) collection.txt文件包含所有信息,但没有标识哪一件与哪台计算机一起使用

2) 在单台计算机上运行时,有时它看起来像在运行,但从未完成和/或从未报告它已完成或写入文件


是否有其他方法为所有登录计算机的用户收集相同的数据?或者,我只是做得不对吗

更好的方法是使用PSRemoting而不是PSExec

$list = "RemoteComputer1","RemoteComputer2"
Invoke-Command -ComputerName $list -ScriptBlock {get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp -recurse} | Out-File .\collection.txt
如果需要使用PSExec和BAT文件:

PSexec @list.txt -u UserID -p Password PowerShell get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp 
-recurse > collection.txt 2>&1 pause
PSexec @list.txt -u UserID -p Password PowerShell -command $env:computername; get-childitem c:\users -include *.mov,*.avi,*.asf,*.flv,*.swf,*.mpg,*.mp3,*.mp4,*.wmv,*.wav,*.jpg,*.tif,*.png,*.gif,*.bmp -recurse 2>&1 > collection.txt

问题1和2是在远程计算机上运行时出现的。