在我的报告中,当我删除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 : ScopeId : 000.11.2.3 IPAddress : 111.22.3.444 HostName : NOPE00112233 ClientID : 00-11-22-33-44-55 AddressState : ActiveReservation
NOPEDH01 : ScopeId : 000.11.2.3 IPAddress : 111.22.3.445 HostName : NOPE0011223344 ClientID : 00-11-22-33-44-56 AddressState : 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" -
NoTypeInformationhttps://stackoverflow.com/questions/47565244
复制相似问题