Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 检测远程服务器上的文件_Powershell - Fatal编程技术网

Powershell 检测远程服务器上的文件

Powershell 检测远程服务器上的文件,powershell,Powershell,猜测远程注册表不可用(经过强化的构建使服务无法运行)-我无法查询注册表中的特定值。但是,我正在分析的服务器上存在一个文件,该文件提供了我需要的数据。到目前为止,我已经写了以下内容-如果可以对它进行检查,我将不胜感激,因为它只是挂起-我猜我将受益于父目录的if-exists语句 非常感谢您的建议和帮助(仅在短时间内使用PowerShell,因此请努力解决此问题 Set-ExecutionPolicy RemoteSigned -ErrorAction SilentlyContinue $serv

猜测远程注册表不可用(经过强化的构建使服务无法运行)-我无法查询注册表中的特定值。但是,我正在分析的服务器上存在一个文件,该文件提供了我需要的数据。到目前为止,我已经写了以下内容-如果可以对它进行检查,我将不胜感激,因为它只是挂起-我猜我将受益于父目录的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
您使用的是在远程计算机上具有权限的帐户。如果是,则应提供一个向下的路径。这将从列表中提取服务器名称,并通过\UNC\admin$share进行查询。Serverlist.txt只是以下格式的计算机列表

machinename.domain.com

我看了你的原始请求。你不能循环服务器列表,启动远程注册服务,完成你的工作,然后停止它吗

差不多

$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

您的脚本工作正常,但可能由于您的查询而挂起(听起来好像捕获了太多项)。.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.log

谢谢,我将试一试,不幸的是路径并没有保持不变-路径的子部分是我启动搜索功能的地方。我大概是用$parentPath=“C:\ProgramDataMicrosoft\Microsoft Antimalware\Definition Updates\”来定义它的谢天谢地,虽然我有这个权利,但问题是安全性可能会让我这么做。这个主意太棒了,知道怎么做也很有用。
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.log