# How to export properties into a csv-file

**URL:** <https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032>\
**Category:** PowerShell Help\
**Created:** [November 5, 2013, 8:32pm UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032 "2013-11-05T20:32:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominique-hofmann](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dominique-hofmann](https://forums.powershell.org/u/dominique-hofmann)\
**Post date:** [November 5, 2013, 8:32pm UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/1 "2013-11-05T20:32:28Z")

</div>

Hello Guys  
I have a question…  
I want to export several properties into a csv-file.  
I tried it with export-csv and output-file and it even generated me a file, but it was blank.  
So what could i do so that it generate a file which isn’t blank.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 5, 2013, 10:59pm UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/2 "2013-11-05T22:59:38Z")

</div>

In order for there to be data in the file, you have to pipe something to it. In your other thread, you had a pipeline that was producing zero objects by the time it got to Export-Csv, which will always result in a blank file.

---

<div class="post-metadata">

**Author:** ![dominique-hofmann](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dominique-hofmann](https://forums.powershell.org/u/dominique-hofmann)\
**Post date:** [November 5, 2013, 11:55pm UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/3 "2013-11-05T23:55:19Z")

</div>

i made foreach-object loop and filtered out the properties which value was over 50000.  
Now the script look like this:  
`Param (
[string]$Path = "N:",
[string]$ReportPath = “N:\Test\report.csv”,
[switch]$Recurse
)`

`
Function AddObject {
Param (
$FileObject
)
```
$FileObject
$Size = [double]($FSO.GetFolder($FileObject.FullName).Size)
$Script:TotSize += $Size

# Got rid of the code that converted $Size from a double to a String here

$Script:Report += New-Object PSObject -Property @{
    FolderName = $FileObject.FullName
    CreatedOn = $FileObject.CreationTime
    LastUpdated = $FileObject.LastWriteTime
    Size = $Size
    Owner = (Get-Acl $FileObject.FullName).Owner
}

```
}
Function CalculateSize {
Param (
[double]$Size
)
If ($Size -gt 1000000)
{	$ReturnSize = ($Size / 1GB)
}
Else
{	$ReturnSize = ($Size / 1MB)
}
Return $ReturnSize
}
Function Set-AlternatingRows {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[object]$Lines,
```
    [Parameter(Mandatory=$True)]
   	[string]$CSSEvenClass,
   
    [Parameter(Mandatory=$True)]
    [string]$CSSOddClass
)
Begin {
	$ClassName = $CSSEvenClass
}
Process {
    ForEach ($Line in $Lines)
    {	$Line = $Line.Replace("&lt;tr&gt;","&lt;tr class=""$ClassName""&gt;")
		If ($ClassName -eq $CSSEvenClass)
		{	$ClassName = $CSSOddClass
		}
		Else
		{	$ClassName = $CSSEvenClass
		}
		Return $Line
    }
}

```
}
cls
$Report = @()
$TotSize = 0
$FSO = New-Object -ComObject Scripting.FileSystemObject
#First get the properties of the starting path
$Root = Get-Item -Path $Path
AddObject $Root
#Now loop through all the subfolders
$ParamSplat = @{
Path = $Path
Recurse = $Recurse
}
ForEach ($Folder in (Get-ChildItem @ParamSplat | Where { $_.PSisContainer }))
{
AddObject $Folder
}
$Report | ForEach-Object {
```
If($_.Size -gt 500000) {
    write-host $_.Size ,$_.Owner ,$_.FolderName 

    
}

```
`

`}
`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 6, 2013, 12:01am UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/4 "2013-11-06T00:01:59Z")

</div>

I don’t see any call to Export-Csv or Out-File in your code. Also, you’re using Write-Host inside that foreach-object loop. Write-Host outputs to the console, but does not produce any pipeline output. I’m not sure what you’re trying to accomplish with that bit of code.

If you just want to filter out based on size, it’s better to use Where-Object:

```
$Report |
Where-Object { $_.Size -gt 500000 } |
Whatever
```

---

<div class="post-metadata">

**Author:** ![dominique-hofmann](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@dominique-hofmann](https://forums.powershell.org/u/dominique-hofmann)\
**Post date:** [November 6, 2013, 12:36am UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/5 "2013-11-06T00:36:51Z")

</div>

Thanks Dave Wyatt  
because of the Export-csv i removed it from the code, because it haven’t done anything

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 6, 2013, 1:51am UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/6 "2013-11-06T01:51:08Z")

</div>

Assuming that there are no folders found with sizes greater than your limit, what do you want to be in the files? As I’ve said, if you pipe nothing to Export-Csv, nothing is what you get. It’s possible to work around that, but I don’t know what your requirements are at this point.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/how-to-export-properties-into-a-csv-file/2032/7 "2024-05-16T20:57:34Z")

</div>


