2024-03-28 10:19:24 发布
网友
我需要从VPN连接的远程主机列表中获取时间。你知道吗
这个列表位于一个txt文件中,我想在另一个包含IP和远程机器上注册的时间的文件中输出。你知道吗
我用以下windows powershell代码解决了:
foreach($line in [System.IO.File]::ReadLines("percorso_del_file.txt")) { net time \\$line }
差不多吧。你会得到当地时间。你知道吗
[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
差不多吧。你会得到当地时间。你知道吗
相关问题 更多 >
编程相关推荐