【发布时间】:2022-01-25 07:57:59
【问题描述】:
我使用 powershell 脚本导出所有存在的 DHCP 服务器的列表以及服务器上的范围。结果必须在 python 的第二个脚本中解析。 (这是我们监控的系统)。
这是脚本:
$DHCPServers = (Get-DhcpServerInDC).Dnsname
$Scopes = @()
$Leases = @()
foreach ($DHCPServer in $DHCPServers) {
$Scopes += Get-DhcpServerv4Scope -ComputerName $DHCPServer | select-Object @{Name="DHCPServer"; Expression = {$DHCPServer}},ScopeID,Name,StartRange,EndRange
}
$Scopes | Export-Csv -path .\DHCP_Freeleases-Scopes-get.csv -Encoding utf8 -NoTypeInformation
foreach ($Scope in $Scopes) {
$Leases += Get-DHCPServerv4Lease -ScopeId $Scope.ScopeID -ComputerName $Scope.DHCPServer | select-Object @{Name="DHCPServer"; Expression = {$Scope.DHCPServer}}, IPAddress, @{Name="LeaseExpiryTime"; Expression = {$_.LeaseExpiryTime.toString("yyyy/MM/dd/HH:mm")}}, @{Name="ScopeID"; Expression = {$Scope.ScopeID}}, Addressstate
}
$Leases | Export-Csv -path .\DHCP_Freeleases-Leases-get.csv -Encoding utf8 -NoTypeInformation
当我在本地 DHCP 服务器 (Windows Server 2012 R2) 上编写该脚本时,CSV 导出是我想要的方式:
"dhcp1.server.intern","10.26.9.202","2022/01/25/08:22","172.26.9.192","Active"
现在我将脚本部署到不同的服务器(Windows Server 2019),完全相同的脚本给了我这个 CSVline:
"dhcp1.server.intern","10.26.9.202","2022.01.25.08:22","172.26.9.192","Active"
我想了解它:这怎么可能?我以为 .toString() 会用我的参数给出它?
感谢您的帮助!
【问题讨论】:
-
我想您是在谈论更改的日期分隔符?如果是这样,那通常是一种文化背景。如果不是……请更具体地说明您在说什么。 [咧嘴]
-
是的,我输入了分隔符。谢谢你,我没有想出这个词来做我的研究????
-
我看到你有一个适合你的答案。 很高兴知道! [咧嘴一笑]
标签: powershell csv datetime date-formatting