猜测远程注册表不可用(加强构建,因此服务未运行)-我无法查询注册表以获得特定值。但是,我正在分析的服务器上存在一个文件,它提供了我需要的数据。到目前为止,我已经写了以下内容-如果可以检查一下,因为它只是挂起了-我猜我会从父目录的if exists语句中受益。
非常感谢您的建议和帮助(我使用PowerShell的时间很短,所以努力工作来掌握它。
Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue
$servers = Get-Content -Path C:\Windows\System32\list3.txt
$out = ForEach ($server in $servers)
{
invoke-command -computername $server {Get-ChildItem -Path "C:\ProgramData\Microsoft\Microsoft Antimalware\Definition Updates\" -Exclude Backup -Filter mpavdlta.vdm -Recurse | Select-Object -Last 1 | Select LastWriteTime | ft -AutoSize}
}
$out|Out-File C:\Temp\Versions.log发布于 2015-02-12 21:16:25
$servers = Get-Content -Path "X:\ServerList.txt"
$logfile = "X:\Versions.log"
$Include = "Include.file"
$out = ForEach ($server in $servers)
{
Write-Output(Get-ChildItem -Path "\\$Server\X$\Remote Folder\Structure\" -Exclude Backup -Filter $Include -Recurse | Select-Object -Last 1 | Select LastWriteTime | ft -AutoSize) | Out-File $logFile
}
$out您是否使用在远程计算机上具有权限的帐户。如果是这样的话,这应该提供了一条下降的路径。这将从列表中提取服务器名称,并通过\UNC\admin$共享进行询问。Serverlist.txt只是以下格式的机器列表。
machinename.domain.com
我看过你最初的请求了。你能不能不循环通过serverlist并启动远程注册表服务,做你的工作,然后停止它。
就像这样。
$servers = Get-Content -Path "X:\ServerList.txt"
$Service = "Remote Registry"
$out = ForEach ($server in $servers)
{
Get-Service -Name $Service -ComputerName $Server | Set-Service -Status Running
Do remote reg stuff
Get-Service -Name $Service -ComputerName $Server | Set-Service -Status Stopped
}
$out发布于 2015-02-13 05:54:16
您的脚本可以工作,但它可能会因为您的查询而挂起(听起来它捕获了太多的项)。".vdm“文件是否驻留在该目录中?如果有,您可以删除-Recurse。这是你的修改版本。我刚添加了连接和目的地检查。
Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue
$servers = Get-Content -Path C:\Windows\System32\list3.txt
$out = ForEach ($server in $servers)
{
If(Test-Connection $server -Quiet){
Invoke-Command -Computername $server {
param([string]$parentPath)
If(Test-Path $parentPath)
{
#Write-Host "$parentPath Exists on $env:COMPUTERNAME."
Get-ChildItem -Path $parentPath -Exclude Backup -Filter mpavdlta.vdm -Recurse | Select-Object -Last 1 | Select LastWriteTime | ft -AutoSize
}
Else{
#Write-Host "$parentPath does not exist on $env:COMPUTERNAME"
}
} -ArgumentList $parentPath
}
Else { Write-host "Unable to connect to $server." }
}
$out | Out-File C:\Temp\Versions.loghttps://stackoverflow.com/questions/28472722
复制相似问题