[英]Get the time of a list of remote hosts
I need to get the time from a list of remote hosts connected by a VPN. 我需要从通过VPN连接的远程主机列表中获取时间。
The list is located in a txt file and i would like to have the output in another file containing the IPs and the time registered on the remote machines. 该列表位于txt文件中,我想将输出包含在另一个文件中,该文件包含IP地址和在远程计算机上注册的时间。
I resolved with this code of windows powershell: 我用Windows Powershell的以下代码解决了:
foreach($line in [System.IO.File]::ReadLines("percorso_del_file.txt"))
{
net time \\$line
}
Something like that. 这样的事情。 You will get local time.
您将获得当地时间。
[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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.