【问题标题】:Get the time of a list of remote hosts获取远程主机列表的时间
【发布时间】:2019-12-03 01:45:39
【问题描述】:

我需要从通过 VPN 连接的远程主机列表中获取时间。

该列表位于一个 txt 文件中,我希望将输出保存在另一个文件中,其中包含远程机器上注册的 IP 和时间。

我用这个windows powershell的代码解决了:

foreach($line in [System.IO.File]::ReadLines("percorso_del_file.txt"))
{ 
       net time \\$line
}

【问题讨论】:

  • 你最近有没有尝试过?

标签: python windows powershell time remote-access


【解决方案1】:

类似的东西。您将获得当地时间。

[System.IO.File]::ReadLines("percorso_del_file.txt") | 
    Foreach-Object { 
        $local:computer = $_
        try {
            $local:wmi_os = Get-WmiObject -Class 'win32_operatingsystem' -Property @('localdatetime','__SERVER') -ComputerName $local:computer -ErrorAction Stop
            $local:o = New-Object -TypeName 'PSObject' -Property @{
               ComputerName = $local:wmi_os.'__SERVER';
               Time = $local:wmi_os.ConvertToDateTime($local:wmi_os.localdatetime)
            }
        } catch {
            $local:o = New-Object -TypeName 'PSObject' -Property @{
                ComputerName = $local:computer
                Time = [DateTime]::MinValue
            }
        }
        return $local:o
    } | 
    Export-Csv -LiteralPath 'c:\report.csv' -Encoding UTF32 -Delimiter "`t" -NoTypeInformation

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2012-05-23
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 2014-01-13
    相关资源
    最近更新 更多