【发布时间】:2017-11-30 03:04:07
【问题描述】:
在我的报告中,当我删除 export-csv 部分时,数据会正确显示在屏幕上,当我添加 export-csv 时,不会导出任何数据,但会创建文件。下面是我的脚本,以及当脚本运行(修改)数据的样子时数据的样子。
#Get all DHCP Servers
$ServerList = (Get-Content -Path "\\termserv\DHCPServers.txt")
foreach ($server in $serverlist)
{
#Get the scopes from each serve
Get-DHCPServerv4Scope -ComputerName $server | select ScopeID |
#Get the lease information for each scope
ForEach-Object {Get-DHCPServerv4Lease -ScopeId $_.ScopeId -ComputerName
$server -AllLeases |
where {$_.AddressState -like "*Reservation"} | Select-Object
$server,ScopeId,IPAddress,HostName,ClientID,AddressState | Export-
Csv "\\termserv\d$\term\User\Reservations1.csv"
}
}
在没有 export-csv 的情况下导出的数据是什么样的
NOPEDH01: 范围标识:000.11.2.3 IP地址:111.22.3.444 主机名:NOPE00112233 客户编号:00-11-22-33-44-55 地址状态:ActiveReservation
NOPEDH01: 范围标识:000.11.2.3 IP地址:111.22.3.445 主机名:NOPE0011223344 客户编号:00-11-22-33-44-56 地址状态:ActiveReservation
更新:尝试过,但仍然没有,当我在我的 DH 服务器上本地运行脚本的修改版本时,它可以正常运行,但我正在查看我的环境中的近 100 台 DH 服务器,见下文
Get-DHCPServerV4Scope | ForEach {
Get-DHCPServerv4Lease -ScopeID $_.ScopeID -AllLeases | where
{$_.AddressState -like '*Reservation'}
} | Select-Object ScopeId,IPAddress,HostName,ClientID,AddressState | Export-
Csv "\\termserv\d$\term\$($env:COMPUTERNAME)-Reservations1.csv" -
NoTypeInformation
【问题讨论】:
标签: excel powershell csv