# Custom Format Views

**URL:** <https://forums.powershell.org/t/custom-format-views/11289>\
**Category:** PowerShell Help\
**Created:** [September 10, 2018, 4:17am UTC](https://forums.powershell.org/t/custom-format-views/11289 "2018-09-10T04:17:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 10, 2018, 4:17am UTC](https://forums.powershell.org/t/custom-format-views/11289/1 "2018-09-10T04:17:28Z")

</div>

HI,

I created a custom formatted view as below:

$currentdate = get-date

$currentdate = $currentdate.ToString(‘MM-dd-yyyy\_hh-mm-ss’)

update-formatdata -prependpath C:\scripts\datest.format.ps1xml

get-da8stats -computername localhost

When I run the above function, I get the desired column header output mentioned in datest.format.ps1xml. But, when I export this to csv, the column headers are different again.

get-da8stats -computername localhost | export-csv -path “C:\test\_$currentdate.csv”

Pics at the link: [https://drive.google.com/open?id=1UFFRVqGyB361Pg8PR\_CnrSkTFTYCQ3Dv](https://drive.google.com/open?id=1UFFRVqGyB361Pg8PR_CnrSkTFTYCQ3Dv)

&nbsp;

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [September 10, 2018, 5:26am UTC](https://forums.powershell.org/t/custom-format-views/11289/2 "2018-09-10T05:26:42Z")

</div>

You probably want to use select-object, not update-formatdata. Those format files are only for the screen.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 10, 2018, 7:47am UTC](https://forums.powershell.org/t/custom-format-views/11289/3 "2018-09-10T07:47:19Z")

</div>

Yes, and all formatting cmdlets are only for printing the output in console, it shouldn’t be used between pipelines but at the end of the pipeline, using it between the pipeline will convert the objects to text which is useful only in console.

---

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 10, 2018, 8:50pm UTC](https://forums.powershell.org/t/custom-format-views/11289/4 "2018-09-10T20:50:37Z")

</div>

Okay, thank you JS 🙂

---

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 10, 2018, 8:52pm UTC](https://forums.powershell.org/t/custom-format-views/11289/5 "2018-09-10T20:52:10Z")

</div>

Thanks KV 🙂

---

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 10, 2018, 9:20pm UTC](https://forums.powershell.org/t/custom-format-views/11289/6 "2018-09-10T21:20:17Z")

</div>

This is the code I am using to generate Csv file which contains Columns ComputerName, Memory %, CPU %, RAM(GB), No.Of Processors, Connections in order. I am getting the same when I run in powershell.exe, but format changes when I export to CSV. Can someone modify this and help me. Thank you.

function Get-DA8Stats

{

[cmdletbinding()]

param

(

[parameter(mandatory=$True, ValueFromPipeline=$true, HelpMessage=“Computer name or IP address”)]

[ValidateCount(1,40)]

[ValidateNotNullOrEmpty()]

[string]$ComputerName

&nbsp;

&nbsp;

)

begin

{}

process

{

foreach ($computer in $ComputerName)

{

$memorysize = [math]::round((Get-WmiObject -ClassName Win32\_OperatingSystem -ComputerName $computer).TotalVisibleMemorySize / 1mb)

$numberofprocessors = Get-WmiObject -ClassName Win32\_computersystem -ComputerName $computer | select-object NumberOfLogicalProcessors

$daconnections = Get-RemoteAccessConnectionStatisticsSummary -ComputerName $computer | Select-Object totaldaconnections

$proc = Get-WmiObject -computername $computer win32\_processor | Measure-Object -property LoadPercentage -Average | Select-Object Average

$mem = gwmi -Class win32\_operatingsystem -computername $computer | Select-Object @{Name = “MemoryUsage”; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)\*100)/ $\_.TotalVisibleMemorySize) }}

$paras = @{“RAM(GB)” = $memorysize;

“No.Of Processors” = $numberofprocessors.numberoflogicalprocessors;

“ComputerName” = $computer;

“Connections” = $daconnections.totaldaconnections;

“Memory %” = $mem.memoryusage;

“CPU %” = $proc.average

}

$obj = New-Object -TypeName psobject -Property $paras

$obj.psobject.typenames.insert(0, “DA.SystemInfo”)

Write-Output $obj

}

}

end {}

&nbsp;

}

&nbsp;

$CurrentDate = Get-Date

$CurrentDate = $CurrentDate.ToString(‘MM-dd-yyyy\_hh-mm-ss’)

Update-FormatData -PrependPath C:\scripts\DATest.format.ps1xml

Get-DA8Stats -ComputerName (Get-Content -Path C:\test\servers.txt) | Export-Csv -NoTypeInformation -Path “C:\DA8Data\_$CurrentDate.csv”

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 11, 2018, 12:43am UTC](https://forums.powershell.org/t/custom-format-views/11289/7 "2018-09-11T00:43:39Z")

</div>

I request you to update the above post by formating the code properly which makes others to easily understand your code, below link will help you.

- [How to format code in this forum](https://powershell.org/forums/topic/how-to-format-code-in-the-forums/)

---

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 11, 2018, 12:56am UTC](https://forums.powershell.org/t/custom-format-views/11289/8 "2018-09-11T00:56:01Z")

</div>

Hi KV, thanks for the reply.

> <https://gist.github.com/raghuacc/cbd8548b1b7d455a5a59e4f3d4dfc8bf>

Let me know if above link is ok. Apologies for inconvenience as I am new to this. Thank you.

---

<div class="post-metadata">

**Author:** ![ta11ow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ta11ow/32/131_2.png) [@ta11ow](https://forums.powershell.org/u/ta11ow)\
**Post date:** [September 11, 2018, 7:14am UTC](https://forums.powershell.org/t/custom-format-views/11289/9 "2018-09-11T07:14:27Z")

</div>

Format.ps1xml files are purely for display formatting. The objects in question still retain their original properties, which are what is exported to CSV.

If you want to alter those, I’d recommend using Select-Object, Add-Member, or just building your own custom object with the properties you need. If I understand correctly, the issue is the ordering of the columns? This is an issue because hashtables do not store the order of properties. In PS v3 and up, you can use [ordered] to force the hashtable to be an ordered collection type instead, but there’s a simpler way:

```
$Obj = [PSCustomObject]@{
    "RAM(GB)" = $memorysize
    "No.Of Processors" = $numberofprocessors.numberoflogicalprocessors
    "ComputerName" = $computer
    "Connections" = $daconnections.totaldaconnections
    "Memory %" = $mem.memoryusage
    "CPU %" = $proc.average
}
$Obj | Export-Csv -Path $FilePath
```

---

<div class="post-metadata">

**Author:** ![raghavendra-b](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@raghavendra-b](https://forums.powershell.org/u/raghavendra-b)\
**Post date:** [September 11, 2018, 8:34am UTC](https://forums.powershell.org/t/custom-format-views/11289/10 "2018-09-11T08:34:52Z")

</div>

Thanks Joel, that worked 🙂

---

<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:34pm UTC](https://forums.powershell.org/t/custom-format-views/11289/11 "2024-05-16T20:34:30Z")

</div>

Closed on May 16, 2024, 8:34pm UTC


