Loyall
asked on
Powershell : Pipe results to CSV file
Hi,
I feel quite stupid, 'cause for some reason I cannot get the results of a powershellscript piped to a csv file.
I tried to place:
| Select @{N="Name";E={$Name}},@{N= "Status";E ={$status} }
in combination with:
| Export-Csv D:\PC_ip-info.csv -Delimiter ";" -notype
But it gives me, or: only the results of the last computername of the imported csv, or the: "An empty pipe element is not allowed" error.
I did not place the pipe "|" at the start of an empty line.
This is the script. I would like to have the returned ip values to be exported to a csv file
I feel quite stupid, 'cause for some reason I cannot get the results of a powershellscript piped to a csv file.
I tried to place:
| Select @{N="Name";E={$Name}},@{N=
in combination with:
| Export-Csv D:\PC_ip-info.csv -Delimiter ";" -notype
But it gives me, or: only the results of the last computername of the imported csv, or the: "An empty pipe element is not allowed" error.
I did not place the pipe "|" at the start of an empty line.
This is the script. I would like to have the returned ip values to be exported to a csv file
$ErrorActionPreference = "SilentlyContinue"
$CSVFile = "D:\Import_Computers.csv"
$Computer = import-csv $CSVFile -delimiter ';'
Write-Host "Name| NetworkCard | IP | SUBNET | GateWay | MacADD | DNS " -ForegroundColor Green
foreach ( $Computer in $Computer )
{
if (Test-Connection $Computer.workstations -Count 1 -ErrorAction SilentlyContinue)
{
$nwINFO = Get-WmiObject -ComputerName $Computer.workstations Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null }
$nwServerName = $nwINFO.DNSHostName
$nwDescrip = $nwINFO.Description
$nwIPADDR = $nwINFO.IPAddress
$nwSUBNET = $nwINFO.IpSubnet
$nwGateWay = $nwINFO.DefaultIPGateway
$nwMacADD = $nwINFO.MACAddress
$nwDNS = $nwINFO.DNSServerSearchOrder
# Server/CompName |NetworkCard | IPAdress | SubnetMask| Gateway | MAC Address| DNS |
Write-Host "$nwServerName | $nwDescrip | $nwIPADDR | $nwSUBNET | $nwGateWay | $nwMacADD | $nwDNS " | ft *
}
else
{
write-host $Computer.workstations "is not pingable" -ForegroundColor Yellow
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.