{"id":12081,"date":"2011-11-15T00:01:00","date_gmt":"2011-11-15T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/11\/15\/see-why-powershell-cant-export-some-properties-to-csv\/"},"modified":"2011-11-15T00:01:00","modified_gmt":"2011-11-15T00:01:00","slug":"see-why-powershell-cant-export-some-properties-to-csv","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/see-why-powershell-cant-export-some-properties-to-csv\/","title":{"rendered":"See Why PowerShell Can&#039;t Export Some Properties to CSV"},"content":{"rendered":"<p><b>Summary:<\/b> Learn why Windows PowerShell cannot export certain properties to a CSV file and what to do about it.<\/p>\n<p>&nbsp;<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. The other day, Terry Dow posted a comment on my <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/09\/23\/use-powershell-to-work-with-csv-formatted-text.aspx?CommentPosted=true#comments\">Use PowerShell to Work with CSV Formatted Text<\/a> blog post. Basically, Terry is asking about exporting a multivalue property via <b>Export-CSV<\/b> file. I can illustrate the problem by using the <b>Get-Process<\/b> cmdlet to retrieve information about my currently running Outlook process. In this command, I pipe the results of the <b>Get-Process<\/b> cmdlet to the <b>Format-List<\/b> cmdlet. Here is the command:<\/p>\n<p style=\"padding-left: 30px\">Get-Process outlook | format-list *<\/p>\n<p>The output is really extensive, and I am going to point out that one line appears like the one seen here:<\/p>\n<p style=\"padding-left: 30px\">Threads&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : {7148, 8120, 5320, 3080&#8230;}<\/p>\n<p>I am now going to select the <b>name<\/b><i> <\/i>and the <b>threads<\/b><i> <\/i>properties, and pipe them to the <b>Format-List<\/b> cmdlet:<\/p>\n<p style=\"padding-left: 30px\">Get-Process outlook | format-list name, threads<\/p>\n<p>The output does not contain all of the thread information. In fact, it only has a few numbers, followed by an ellipsis. I try several combinations, but nothing other than a few numbers and ellipses ever appear. This is shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8176.hsg-11-15-11-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8176.hsg-11-15-11-1.png\" alt=\"Image of unsatisfactory output\" title=\"Image of unsatisfactory output\" \/><\/a><\/p>\n<p>This behavior carries over when piping information to <b>Export-CSV<\/b>. In the following command I use the <b>Get-Process<\/b> cmdlet to retrieve the Outlook process. I pipe the resultant <b>Process<\/b> object to the <b>Select-Object<\/b> cmdlet (<b>select<\/b> is an alias) and retrieve the name and the threads, and pipe to <b>Export-CSV<\/b> to create a CSV file. I then open the file in Microsoft Excel.<\/p>\n<p style=\"padding-left: 30px\">Get-Process outlook | Select name, threads | export-CSV c:\\fso\\olproc.csv; c:\\fso\\olproc.csv<\/p>\n<p>The resultant Microsoft Excel spreadsheet appears in the following figure (I highlighted the threads collection manually).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8831.HSG-11-15-11-2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8831.HSG-11-15-11-2.png\" alt=\"Image of resultant Excel spreadsheet\" title=\"Image of resultant Excel spreadsheet\" \/><\/a><\/p>\n<p>So, we have confirmed that for certain types of properties, Windows PowerShell does not display all the information. We seem to be a bit better off when using <b>Format-Table<\/b> or <b>Format-List<\/b> (but that is just an illusion).<\/p>\n<p>The first thing we need to do is to see which type of object we are dealing with. To do this, I use the <b>Get-Member<\/b> cmdlet. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Process outlook | Get-Member threads<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; TypeName: System.Diagnostics.Process<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">MemberType<\/span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Definition<\/span><\/p>\n<p style=\"padding-left: 30px\">Threads Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.ProcessThreadCollection&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Threads {get;}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The <b>threads<\/b><i> <\/i>property returns a <b>ProcessThreadCollection<\/b>. This <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.diagnostics.processthreadcollection.aspx\">class is documented on MSDN<\/a>, but I do not need to really look at that article because I can find out what I need via the <b>Get-Member<\/b> cmdlet. The big thing to keep in mind is that a <b>ProcessThreadCollection<\/b> class is a collection of something else. This something else is a <b>ProcessThread<\/b>. The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.diagnostics.processthread.aspx\">ProcessThread class is also documented on MSDN<\/a>, and it is more interesting than the <b>ProcessThreadCollection<\/b>. I can find the information about the <b>ProcessThread<\/b> class by using the following command (<b>gm<\/b> is an alias for the <b>Get-Member<\/b> cmdlet):<\/p>\n<p style=\"padding-left: 30px\">(Get-Process outlook).threads | gm<\/p>\n<p style=\"padding-left: 30px\">The command and associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; (Get-Process outlook).threads | gm<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; TypeName: System.Diagnostics.ProcessThread<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style=\"text-decoration: underline\">MemberType<\/span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Definition<\/span><\/p>\n<p style=\"padding-left: 30px\">Disposed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Event&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.EventHandler Disposed(System.Object, System.EventArgs)<\/p>\n<p style=\"padding-left: 30px\">CreateObjRef&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)<\/p>\n<p style=\"padding-left: 30px\">Dispose &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Void Dispose()<\/p>\n<p style=\"padding-left: 30px\">Equals&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bool Equals(System.Object obj)<\/p>\n<p style=\"padding-left: 30px\">GetHashCode&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int GetHashCode()<\/p>\n<p style=\"padding-left: 30px\">GetLifetimeService&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Object GetLifetimeService()<\/p>\n<p style=\"padding-left: 30px\">GetType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type GetType()<\/p>\n<p style=\"padding-left: 30px\">InitializeLifetimeService&nbsp;&nbsp; Method &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Object InitializeLifetimeService()<\/p>\n<p style=\"padding-left: 30px\">ResetIdealProcessor &nbsp; &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Void ResetIdealProcessor()<\/p>\n<p style=\"padding-left: 30px\">ToString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string ToString()<\/p>\n<p style=\"padding-left: 30px\">BasePriority &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Int32 BasePriority {get;}<\/p>\n<p style=\"padding-left: 30px\">Container &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.ComponentModel.IContainer Container {get;}<\/p>\n<p style=\"padding-left: 30px\">CurrentPriority&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Int32 CurrentPriority {get;}<\/p>\n<p style=\"padding-left: 30px\">Id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Int32 Id {get;}<\/p>\n<p style=\"padding-left: 30px\">IdealProcessor&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Int32 IdealProcessor {set;}<\/p>\n<p style=\"padding-left: 30px\">PriorityBoostEnabled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Boolean PriorityBoostEnabled {get;set;}<\/p>\n<p style=\"padding-left: 30px\">PriorityLevel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.ThreadPriorityLevel PriorityLevel {get;set;}<\/p>\n<p style=\"padding-left: 30px\">PrivilegedProcessorTime Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.TimeSpan PrivilegedProcessorTime {get;}<\/p>\n<p style=\"padding-left: 30px\">ProcessorAffinity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IntPtr ProcessorAffinity {set;}<\/p>\n<p style=\"padding-left: 30px\">Site&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.ComponentModel.ISite Site {get;set;}<\/p>\n<p style=\"padding-left: 30px\">StartAddress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IntPtr StartAddress {get;}<\/p>\n<p style=\"padding-left: 30px\">StartTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.DateTime StartTime {get;}<\/p>\n<p style=\"padding-left: 30px\">ThreadState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.ThreadState ThreadState {get;}<\/p>\n<p style=\"padding-left: 30px\">TotalProcessorTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.TimeSpan TotalProcessorTime {get;}<\/p>\n<p style=\"padding-left: 30px\">UserProcessorTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.TimeSpan UserProcessorTime {get;}<\/p>\n<p style=\"padding-left: 30px\">WaitReason&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Diagnostics.ThreadWaitReason WaitReason {get;}<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>I can write the threads to a CSV file. To do this, I can use the <b>Select-Object<\/b> cmdlet and pipe the results to the <b>Export-CSV<\/b> file. This command is shown here (I use <b>Select<\/b> as an alias for the <b>Select-Object<\/b> cmdlet, and I open the CSV in Microsoft Excel by using the path to the newly created CSV file):<\/p>\n<p style=\"padding-left: 30px\">Get-Process outlook | Select -ExpandProperty threads | Export-CSV c:\\fso\\OlThread.csv;c:\\fso\\olthread.csv<\/p>\n<p>The newly created CSV file opens easily in Microsoft Excel. This allows me to examine the various threads in Microsoft Outlook (they are all waiting by the way).<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5277.hsg-11-15-11-3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5277.hsg-11-15-11-3.png\" alt=\"Image of newly created CSV file opened in Excel\" title=\"Image of newly created CSV file opened in Excel\" \/><\/a><\/p>\n<p>So the solution to having an object name showing up in the CSV file is to use the <b>Select-Object<\/b> cmdlet to expand the object contained inside the property. Keep in mind that this will not enable you to be able to have the process name, <b>processID<\/b>, and threads in the same CSV file because of the way <b>Select-Object<\/b> works when expanding processes.<\/p>\n<p>Use <b>Export-CliXML<\/b> to maintain fidelity to the original object. The following code illustrates this technique:<\/p>\n<p style=\"padding-left: 30px\">Get-Process outlook | Export-Clixml c:\\fso\\olXML.xml<\/p>\n<p>To work with the object, use the <b>Import-Clixml<\/b> cmdlet as illustrated here where I import the XML file, and access the <b>name<\/b> and the <b>process ID<\/b>.<\/p>\n<p style=\"padding-left: 30px\">$a = Import-Clixml C:\\fso\\olXML.xml<\/p>\n<p style=\"padding-left: 30px\">$a.Name<\/p>\n<p style=\"padding-left: 30px\">$a.Id<\/p>\n<p>I get all of the thread information by accessing the <b>threads<\/b><i> <\/i>property. In the following example, I truncate the output:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $a.threads&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">BasePriority&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 8<\/p>\n<p style=\"padding-left: 30px\">CurrentPriority&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 13<\/p>\n<p style=\"padding-left: 30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7148<\/p>\n<p style=\"padding-left: 30px\">PriorityBoostEnabled&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"padding-left: 30px\">PriorityLevel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Normal<\/p>\n<p style=\"padding-left: 30px\">&lt;***OUTPUT TRUNCATED***&gt;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>Remember back at the beginning of the article when I was talking about the <b>ProcessThreadCollection<\/b> class? I said the <b>ProcessThreadCollection<\/b> class was not so interesting. Well, there is one interesting property, and it is the <b>count<\/b><i> <\/i>property. I can use dotted notation to access it, as illustrated here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $a.threads.count<\/p>\n<p style=\"padding-left: 30px\">39<\/p>\n<p>Knowing the number of threads a process uses is valuable information. In fact, using the technique above, I can add it to an object by using the following technique (<b>gps<\/b> is an alias for the <b>Get-Process<\/b> cmdlet and <b>select<\/b> is an alias for <b>Select-Object<\/b>):<\/p>\n<p style=\"padding-left: 30px\">gps | select name, @{LABEL=&#8217;number of threads&#8217;;EXPRESSION= {$_.threads.count}}<\/p>\n<p>This code works, but the <i>number of threads<\/i> is spread out everywhere (not sorted). To sort the number of threads, I pipe the command to the <b>Sort-Object<\/b> cmdlet. My label, <i>number of threads,<\/i> is the actual property name in my newly created custom object. This command is shown here:<\/p>\n<p style=\"padding-left: 30px\">gps | select name, @{LABEL=&#8217;number of threads&#8217;;EXPRESSION= {$_.threads.count}} | sort &#8216;number of threads&#8217;<\/p>\n<p>This works great, but now the information spreads to both sides of the Windows PowerShell console window. Now, I will use the <b>Format-Table<\/b> cmdlet (<b>ft<\/b> is an alias and <b>a<\/b><i> <\/i>is short for <b>autosize<\/b>).<i> <\/i><\/p>\n<p style=\"padding-left: 30px\">gps | select name, @{LABEL=&#8217;number of threads&#8217;;EXPRESSION= {$_.threads.count}} | sort &#8216;number of threads&#8217; | ft &ndash;a<\/p>\n<p>The command and associated output are shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4062.hsg-11-15-11-4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4062.hsg-11-15-11-4.png\" alt=\"Image of command and associated output\" title=\"Image of command and associated output\" \/><\/a><\/p>\n<p>Of course, it would be possible to pipe this type of expression to Export-<b>CSV<\/b>. I hope you enjoyed today&rsquo;s excursions into more fun with CSV files.<\/p>\n<p>Join me tomorrow for more cool Windows PowerShell stuff.<\/p>\n<p>&nbsp;<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p>&nbsp;<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn why Windows PowerShell cannot export certain properties to a CSV file and what to do about it. &nbsp; Microsoft Scripting Guy, Ed Wilson, is here. The other day, Terry Dow posted a comment on my Use PowerShell to Work with CSV Formatted Text blog post. Basically, Terry is asking about exporting a multivalue [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[169,3,4,45,165],"class_list":["post-12081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-csv-and-other-delimited-files","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-xml"],"acf":[],"blog_post_summary":"<p>Summary: Learn why Windows PowerShell cannot export certain properties to a CSV file and what to do about it. &nbsp; Microsoft Scripting Guy, Ed Wilson, is here. The other day, Terry Dow posted a comment on my Use PowerShell to Work with CSV Formatted Text blog post. Basically, Terry is asking about exporting a multivalue [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=12081"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/12081\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=12081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=12081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=12081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}