简体   繁体   中英

Powershell script not displaying IP addresses in CSV file

My goal with this script is to get all machines on the domain into an excel spreadsheet with their IP address in the column next to the name. My script successfully exports the names to the CSV but the IP address field is empty. I have no idea why this is the case as when I print out the output command it shows the name and IP address along with other information about the machine.

Script:

$output = Get-ADComputer -Filter * -Properties IPv4Address
$output | Select-Object -Property name,IPV4Address | Export-Csv -Path c:\temp\IPAudit

Any advice would be appreciated.

THank you, James.

If the very first IP address you query doesn't return an IP address then the field isn't written to the csv, thus ALL subsequent results will not be able to populate the field.

There's lots of ways to code around this but maybe the simplest is to create the csv with fields first:

Set-Content "c:\temp\IPAudit.csv" -Value "Name,IPv4Address"

Then append your content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM