Unable to successfully export Powershell results to CSV

When I execute my PowerShell script in ISE, it completes successfully, but when I add the syntax to export ( |export-csv) the results are blank.

Anyone able to help me out here...?

$computerSystem = Get-CimInstance CIM_ComputerSystem
$computerBIOS = Get-CimInstance CIM_BIOSElement
$computerOS = Get-CimInstance CIM_OperatingSystem
$computerCPU = Get-CimInstance CIM_Processor
$computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$computerName = (Get-WmiObject -Class Win32_ComputerSystem -Property Name)
$computerName1 = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
$IPAddress = (Test-Connection $computerName1 -count 1).IPv4Address.IPAddressToString
Clear-Host

Write-Host "System Information for: " + $computerSystem.Name
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
"HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " Free (" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + $computerOS.ServicePackMajorVersion
"User logged In: " + $computerSystem.UserName
"Last Reboot: " + $computerOS.LastBootUpTime
"ComputerName: " + $computerName.Name
"IP Address: " + $IPAddress  | export-csv c:\results.csv -notype -append

Open in new window

Randy AntesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FOXActive Directory/Exchange EngineerCommented:
try the below

"IP Address: " + $IPAddress  | export-csv 'c:\temp\results.csv' -notypeinformation
0
Randy AntesAuthor Commented:
The directory isnt the issue, I am actually placing the file on my desktop so I know permissions isnt the cause. It is something to do with the syntax of the over all script. When not exported, it works 100%, but no results when exported (blank csv file is created)
0
oBdACommented:
Try it like this:
$ComputerSystem = Get-CimInstance CIM_ComputerSystem
$ComputerBIOS = Get-CimInstance CIM_BIOSElement
$ComputerOS = Get-CimInstance CIM_OperatingSystem
$ComputerCPU = Get-CimInstance CIM_Processor
$ComputerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"

Write-Host "System Information for: " + $ComputerSystem.Name
New-Object -TypeName PSObject -Property ([ordered]@{
	"Manufacturer" =		$ComputerSystem.Manufacturer
	"Model" =				$ComputerSystem.Model
	"Serial Number" =		$ComputerBIOS.SerialNumber
	"CPU" =					$ComputerCPU.Name
	"HDD Capacity" =		"{0:N2}GB" -f ($ComputerHDD.Size/1GB)
	"HDD Space" =			"{0:P2} Free ({1:N2}GB)" -f ($ComputerHDD.FreeSpace/$ComputerHDD.Size), ($ComputerHDD.FreeSpace/1GB)
	"RAM" =					"{0:N2}GB" -f ($ComputerSystem.TotalPhysicalMemory/1GB)
	"Operating System" =	"$($ComputerOS.caption), Service Pack: $($ComputerOS.ServicePackMajorVersion)"
	"User logged In" =		$ComputerSystem.UserName
	"Last Reboot" =			$ComputerOS.LastBootUpTime
	"ComputerName" = 		$ComputerSystem.Name
	"IP Address" =			(Test-Connection $ComputerSystem.Name -count 1).IPv4Address.IPAddressToString
}) | Export-Csv -Path c:\results.csv -NoTypeInformation -Append

Open in new window

3

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
To explain what happened: You wrote the last string only to the file.
Writing a string with Export-CSV usually results in its length to be written out, if anything.

You always need an object for Export-CSV, a simple data type like integer or string does not work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.