{"id":619,"date":"2014-09-27T00:01:00","date_gmt":"2014-09-27T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/09\/27\/weekend-scripter-why-does-powershell-hide-stuff\/"},"modified":"2014-09-27T00:01:00","modified_gmt":"2014-09-27T00:01:00","slug":"weekend-scripter-why-does-powershell-hide-stuff","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-why-does-powershell-hide-stuff\/","title":{"rendered":"Weekend Scripter: Why Does PowerShell Hide Stuff?"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about how Windows PowerShell decides what to display.<\/span>\nMicrosoft Scripting Guy, Ed Wilson, is here. This morning I received an email from a friend with whom I used to work a long time ago. (He was one of the reviewers on the WMI book I wrote in the VBScript days.) Here is his email:\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;Hey, Mr. Ed!&nbsp;How are you and the Scripting Wife? Hope you are well! I enjoy seeing your Facebook posts about your antics with your personal trainer. I have a quick Windows PowerShell question for you that has been nagging me for a while. I have a simple script that runs via Group Policy at computer startup:<\/p>\n<p style=\"margin-left:30px\">$computername = gc env:computername<\/p>\n<p style=\"margin-left:30px\">$applications= Get-WmiObject Win32_ComputerSystem<\/p>\n<p style=\"margin-left:30px\">$applications | out-file &#8220;\\serversharecomputerWin32_ComputerSystem$computername.txt&#8221;\nThe output of this script contains only a few of the many properties of the Win32_ComputerSystem class. Specifically, they are <b>Domain<\/b>, <b>Manufacturer<\/b>, <b>Model<\/b>, <b>Name<\/b>, <b>PrimaryOwnerName<\/b>, and <b>TotalPhysicalMemory<\/b>.\nBut the Win32_ComputerSystem has lots more properties than that. When I type the following command, the *.csv file contains all of the properties: &nbsp;<\/p>\n<p style=\"margin-left:30px\">$applications | export-csv &#8220;\\serversharecomputerComputerSystem$computername.csv&#8221;\nHow does <b>Out-File<\/b> have the audacity to pick and choose which properties to write to the file, and how does it chose them? Is there a way to tell it to write all of the properties without having to hand pick them?\n~Dave\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Here is my reply&#8230;\nHi Dave,\nIt&rsquo;s great to hear from you. <b>Out-File<\/b> is simply redirecting a standard output stream. With many of the WMI classes, such as Win32_ComputerSystem, we have a Format*xml file that we created to select the main properties of interest from the WMI class. The file is called DotNetTypes.format.ps1xml and it is located in the <b>$pshome<\/b> directory (which normally resolves to C:WindowsSystem32WindowsPowerShellv1.0). You can create your own Format*xml file and choose additional properties, but that is hard core.\nYour variable, <b>$applications<\/b>, will hold the deserialized Win32_ComputerSystem object and permit you to call methods and access all of the properties.\nBut when you send it to the output formatter, it will use the format from the Format*xml file.<span style=\"font-size:12px\">This is the same as typing <\/span><b style=\"font-size:12px\">gwmi win32_computersystem<\/b><span style=\"font-size:12px\"> at the Windows PowerShell console. Only the main properties display.<\/span>\nYou can get around this by using <b>Select-Object<\/b> (or <b>Format-List<\/b>\/<b>Table<\/b>) to choose <b>*<\/b>. This will retrieve all of the properties that are available from the Win32_ComputerSystem WMI class. Here is an example of how you might approach this:<\/p>\n<p style=\"margin-left:30px\">gwmi win32_computersystem<br \/> $c = gwmi win32_computersystem<br \/> $c<br \/> $c | select *\nNow you can redirect or use <b>Out-File<\/b> to send the returned information to a text file:<\/p>\n<p style=\"margin-left:30px\">$c | select * &gt;&gt; c:fsoc.txt<\/p>\n<p style=\"margin-left:30px\">$c | select * | Out-File c:fsoc.txt\nBy default, te reason you get the complete information is that <b>Export-CSV<\/b> is creating a deserialized object represented as a CSV file. You can even reconstitute the object by using <b>Import-CSV<\/b>. This is a different output stream.\nTo select specific properties going to <b>Export-CSV<\/b>, you can again use the <b>Select<\/b> object&mdash;but this time, only select the specific properties:<\/p>\n<p style=\"margin-left:30px\">$c | select Domain, Name, Manufacturer, Model | Export-Csv c:fsoc.csv\nHope all is well with you, and that this information helps clarify what you have been seeing. Stay in touch.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto: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.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about how Windows PowerShell decides what to display. Microsoft Scripting Guy, Ed Wilson, is here. This morning I received an email from a friend with whom I used to work a long time ago. (He was one of the reviewers on the WMI book I wrote in the [&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":[479,3,4,61,45],"class_list":["post-619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-output","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about how Windows PowerShell decides what to display. Microsoft Scripting Guy, Ed Wilson, is here. This morning I received an email from a friend with whom I used to work a long time ago. (He was one of the reviewers on the WMI book I wrote in the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/619","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=619"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/619\/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=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}