I’m attempting to import some data in, pc names, check it for various things…run a couple of apps…then export a list of pc’s which fit what i’m looking for…Everything seems to work except that when i export the data, it shows up as Length = 10 everytime instead of the name of pc. Here’s an edited snipit of the troublesome bit. When attempting to pipe out $Name, it exports to the file, but this is what ends up in the file (the length of the pc name…all 7 pc names are 10 digits in length for the testing being done now):<\/p>\n
#TYPE<\/span> System.String Length 10 10 10 10 10 10 10<\/p>\n $ComputerNameALL = import-csv .\\pcslimited.csv | select -expandproperty PC<\/p>\n write-host “Verifying PCs from List (This could take up to 30 min)” Foreach ($Name in $ComputerNameALL) I’m attempting to import some data in, pc names, check it for various things…run a couple of apps…then export a list of pc’s which fit what i’m looking for…Everything seems to work except that when i export the data, it shows up as Length = 10 everytime instead of the name of pc. Here’s an edited snipit of the troublesome bit. When attempting to pipe out $Name, it exports to the file, but this is what ends up in the file (the length of the pc name…all 7 pc names are 10 digits in length for the testing being done now):<\/p>\n #TYPE<\/span> System.String Length 10 10 10 10 10 10 10<\/p>\n $ComputerNameALL = import-csv .\\pcslimited.csv | select -expandproperty PC<\/p>\n write-host “Verifying PCs from List (This could take up to 30 min)” Foreach ($Name in $ComputerNameALL) Export-Csv is designed to export an object with properties to CSV. A string’s only property is Length, which is why your spreadsheet contains “Length 10.” You can use Out-File instead of Export-Csv. For example:<\/p>\n Also, please use the </> button in the toolbar to post code. That makes it easier to read than the plain-text format that Spiceworks uses.<\/p>\n Welcome to the community.<\/p>","upvoteCount":3,"datePublished":"2021-01-14T14:06:06.000Z","url":"https://community.spiceworks.com/t/ps-import-export-csv/787408/2","author":{"@type":"Person","name":"Evan7191","url":"https://community.spiceworks.com/u/Evan7191"}},{"@type":"Answer","text":" Try,<\/p>\n or<\/p>\n Evan pretty much got you covered.<\/p>\n The issue is that the only property the string has is the length and export-csv needs more properties to export is successfully.<\/p>\n If you use EXPANDPROPERTY, it strips away ALL other properties, so you want to be careful with that.<\/p>\n In general, If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n
\n
\nwrite-host “”<\/p>\n
\n{
\nif (test-connection $Name -count 1 -quiet)
\n{
\nif (@(get-adcomputer $name))
\n{
\nwrite-host $Name \" Exists in AD and DNS\"
\n$Name | export-csv C:\\temp2\\PCCheck\\ComputersFound.csv -append #| select -expandproperty -header a
\n}
\n}
\n}<\/p>","upvoteCount":4,"answerCount":8,"datePublished":"2021-01-14T13:07:13.000Z","author":{"@type":"Person","name":"spiceuser-aq0j3","url":"https://community.spiceworks.com/u/spiceuser-aq0j3"},"suggestedAnswer":[{"@type":"Answer","text":"
\n
\nwrite-host “”<\/p>\n
\n{
\nif (test-connection $Name -count 1 -quiet)
\n{
\nif (@(get-adcomputer $name))
\n{
\nwrite-host $Name \" Exists in AD and DNS\"
\n$Name | export-csv C:\\temp2\\PCCheck\\ComputersFound.csv -append #| select -expandproperty -header a
\n}
\n}
\n}<\/p>","upvoteCount":4,"datePublished":"2021-01-14T13:07:13.000Z","url":"https://community.spiceworks.com/t/ps-import-export-csv/787408/1","author":{"@type":"Person","name":"spiceuser-aq0j3","url":"https://community.spiceworks.com/u/spiceuser-aq0j3"}},{"@type":"Answer","text":"$ComputerNameALL = import-csv .\\pcslimited.csv | select -expandproperty PC\n\nwrite-host \"Verifying PCs from List (This could take up to 30 min)\"\nwrite-host \"\"\n\nForeach ($Name in $ComputerNameALL) \n{ \n if (test-connection $Name -count 1 -quiet) \n {\n if (@(get-adcomputer $name))\n {\n write-host $Name \" Exists in AD and DNS\"\n $Name | Out-File C:\\temp2\\PCCheck\\ComputersFound.csv -append\n }\n }\n}\n<\/code><\/pre>\n
$ComputerNameALL = import-csv .\\pcslimited.csv | select -expandproperty PC\n$data=Foreach ($Name in $ComputerNameALL)\n{\n if (test-connection $Name -count 1 -quiet)\n {\n if (@(get-adcomputer $name))\n {\n write-host $Name \" Exists in AD and DNS\"\n \n }\n }\n}\n\n$data|export-csv c:\\list.csv -NoTypeInformation\n<\/code><\/pre>\n
Ipcsv .\\pcslimited.csv|%{if(Test-Connection $_.pc -Count 1){get-adcomputer $_.pc |select @{n='ExistsInAdDNS';e={$_.name}}|epcsv c:\\exists.csv -Append -nti}}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-01-14T14:09:43.000Z","url":"https://community.spiceworks.com/t/ps-import-export-csv/787408/3","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"