{"id":979,"date":"2021-08-14T13:46:03","date_gmt":"2021-08-14T12:46:03","guid":{"rendered":"http:\/\/vroamam.com\/wordpress\/?p=979"},"modified":"2021-12-31T18:10:25","modified_gmt":"2021-12-31T17:10:25","slug":"output","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/output\/","title":{"rendered":"Output"},"content":{"rendered":"\n<p>Any output from any PowerShell cmdlet or script is sent to the pipeline, we will look at this in more detail in the next section, the pipeline has some default settings and so if you don&#8217;t tell PowerShell where to send what&#8217;s on the pipeline it will use it&#8217;s default settings.<\/p>\n\n\n\n<p>The default output is normally your screen or console.<\/p>\n\n\n\n<p>PowerShell also does not output text. It may look that way but what it actually puts on the pipeline are objects. An object is just a data structure that consists of one or more things. You can think of it in terms of a database record with a number of fields and values. Your output could be more than one record, a collection of records if you like. In PowerShell they refer to it simply as a collection.<\/p>\n\n\n\n<p>What does this look like in a PowerShell and how do we know what kind of object is returned? Well we got back to our old friend <code>Get-Member<\/code> <\/p>\n\n\n\n<p>The first thing we see returned from the Get-Member output is the type of object the command returns<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"596\" height=\"68\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-10.png\" alt=\"\" class=\"wp-image-980\"\/><figcaption>PowerShell console showing a cropped output of Get-Process piped to Get-Member showing the returned object type  <\/figcaption><\/figure>\n\n\n\n<p>Then we get all the &#8220;field names&#8221; and &#8220;datatypes&#8221; just like we would have in a database for each record, or maybe for each row in a spreadsheet, I couldn&#8217;t fit them all in one screen so here is a sample?:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"903\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-11.png\" alt=\"\" class=\"wp-image-981\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-11.png 883w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-11-768x785.png 768w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><figcaption>Powershell console showing cropped output of Get-Process when piped into Get-Member. It lists some of the members of Get-Process<\/figcaption><\/figure>\n\n\n\n<p>The Get-Process cmdlet has 92 different methods, properties, sets or aliases in its object type System.Diagnostics.Process<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"207\" height=\"144\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-12.png\" alt=\"\" class=\"wp-image-982\"\/><figcaption>An Image showing the summation of member types in object System.Diagnostics.Process<\/figcaption><\/figure>\n\n\n\n<p>OK, so an object can have one or more parts to it what are those parts?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Property <\/strong>&#8211; This is what holds the value, the actual data we want.<\/li><li><strong>Method<\/strong> &#8211; An action that can be performed on the object <\/li><li><strong>ScriptProperty<\/strong> &#8211; these are used to calculate property values<\/li><li><strong>AliasProperty<\/strong> &#8211; As its names suggest, it is an alias to another property<\/li><li><strong>Event <\/strong>&#8211; These are .NET events linked to the object.<\/li><li><strong>PropertySet <\/strong>&#8211; Unsurprisingly, it holds a set of properties.<\/li><li><strong>NoteProperty<\/strong> &#8211; Simply hold static property names<\/li><\/ul>\n\n\n\n<p>Let&#8217;s look at these in a bit more detail<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Property<\/h2>\n\n\n\n<p>It holds some data of a predefined type. Property data types are often things like strings, integers, boolean or datetime and they are the data or values that we normally want to see when we run our cmdlet. Name, state, version are all examples of a property<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method<\/h2>\n\n\n\n<p>This is something we don&#8217;t use much as we start out with PowerShell, but you will find you use more as you become more familiar with them.<\/p>\n\n\n\n<p>Let&#8217;s look at the output of Get-Member where we filter only the Methods. there are some that should be obvious, kill, close, refresh, start. These are all called by adding them to the end of the cmdlet<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"741\" height=\"382\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-13.png\" alt=\"\" class=\"wp-image-987\"\/><figcaption>Image of PowerShell console showing members of Get-Process with a MemberType of Method<\/figcaption><\/figure>\n\n\n\n<p>Try this practical example:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<ol class=\"wp-block-list\"><li>Start notepad <\/li><li>Open PowerShell<\/li><li>Run the command <code>get-process -name notepad <\/code><\/li><li>Review the output, you should see the notepad process<\/li><li>Run the command <code>(get-process -name notepad).kill()<\/code><\/li><li>Run the command <code>get-process -name notepad <\/code>again<\/li><\/ol>\n\n\n\n<p>The notepad process no longer exists, you used the <code>kill<\/code> method to stop it from running, the image below shows this in my console:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"283\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-15.png\" alt=\"\" class=\"wp-image-989\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-15.png 794w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-15-768x274.png 768w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><figcaption>Image of a PowerShell Console showing the process details for a process named Notepad<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Alias<\/h2>\n\n\n\n<p>Those used to BASH will understand the concept of aliases. If you haven&#8217;t come across them before they are simply an alternate name for an existing thing often a command or property. PowerShell has a number of built in aliases for the lazy amongst us, we discussed some in the last lesson. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>Select<\/code> is an alias for <code>Select-Object  <\/code>&nbsp;<\/li><li><code>Where<\/code> is an alias for <code>Where-Object<\/code><\/li><\/ul>\n\n\n\n<p>There are other as well, <code>ls<\/code> and <code>dir<\/code> are both aliases for <code>Get-Childitem<\/code><\/p>\n\n\n\n<p>In an object the alias property usually points to an other property. We can investigate this in our <code>Get-Process<\/code> command by looking at what they point to. Call <code>Get-Member<\/code> again but this time look at the member type <code>aliasproperty<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"543\" height=\"220\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-16.png\" alt=\"\" class=\"wp-image-990\"\/><figcaption>Image of a PowerShell console shooing the member of Get-Process with a MemberType of AliasProperty<\/figcaption><\/figure>\n\n\n\n<p>Lets look at the first couple of these:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Handles<\/strong> is an alias for <strong>HandleCount<\/strong><\/li><li><strong>Name<\/strong> is an alias for <strong>ProcessName<\/strong><\/li><\/ul>\n\n\n\n<p>this simply means we can get the same output using the shorter aliases<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"672\" height=\"197\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-17.png\" alt=\"\" class=\"wp-image-991\"\/><figcaption>Image of a PowerShell console showing get-process using alias members and property members producing the same result <\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Output from any PowerShell cmdlet or script is sent to the pipeline, if you don&#8217;t specify differently, it is eventually sent to the default output devices which is normally the console<\/p>\n\n\n\n<p>Output is in the form of objects<\/p>\n\n\n\n<p>Objects are collections of members (these are more commonly referred to as properties but this can get confusing)<\/p>\n\n\n\n<p>Members have different types. Method, Property and Alias are the ones you&#8217;ll use the most.<\/p>\n<\/div><\/div>\n<\/div>\n<\/div>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Further Reading<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.core\/about\/about_objects?view=powershell-7.1\">Microsoft Docs &#8211; About Object<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.core\/about\/about_methods?view=powershell-7.1\">Microsoft Docs &#8211; About Methods<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any output from any PowerShell cmdlet or script is sent to the pipeline, we will look at this in more detail in the next section, the pipeline has some default settings and so if you don&#8217;t tell PowerShell where to send what&#8217;s on the pipeline it will use it&#8217;s default settings. The default output is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[114,3],"tags":[130,128,126,127,81,129,11],"class_list":["post-979","post","type-post","status-publish","format-standard","hentry","category-powershell","category-training","tag-members","tag-methods","tag-objects","tag-pipeline","tag-powershell","tag-properties","tag-training","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/sahuGk-output","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/comments?post=979"}],"version-history":[{"count":9,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/979\/revisions"}],"predecessor-version":[{"id":1120,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/979\/revisions\/1120"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}