{"id":999,"date":"2021-12-31T14:05:01","date_gmt":"2021-12-31T13:05:01","guid":{"rendered":"https:\/\/vroamam.com\/wordpress\/?p=999"},"modified":"2021-12-31T18:10:33","modified_gmt":"2021-12-31T17:10:33","slug":"how-is-it-received-and-handled","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/how-is-it-received-and-handled\/","title":{"rendered":"Pipeline &#8211; How is it Received and Handled"},"content":{"rendered":"\n<p>In the previous section we looked at piping output to another command, we used it mainly to format the output of a command but we also looked briefly at how we might take an action based on the output by using the command <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Get-Process -ProcessName \u2018Notepad\u2019 | stop-process<\/code><\/pre>\n\n\n\n<p>This gets the process ID for the process with the name &#8216;Notepad&#8217; and passes it into the stop-process command, but how do we know that the stop-process command can accept pipeline input and that this input has to be a process id? Here we go back to lesson 3 &#8211; getting help.<\/p>\n\n\n\n<p>If you run the command <code>Get-Help Stop-Process -Full<\/code> you will get a fairly large and complex output but in the middle of it, each accepted parameter is listed with its type and whether or not it can be receive input from the pipeline. In the screen shot below we see an excerpt from this output that demonstrates that <em>Id<\/em> and <em>InputObject<\/em> can be piped into the command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"286\" src=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-1.png\" alt=\"\" class=\"wp-image-1001\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-1.png 822w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-1-768x267.png 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><figcaption>Screen capture showing an excerpt of the output of Get-Help for Stop-Process<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">ByValue<\/h2>\n\n\n\n<p>We can also send the output to the command without telling it what is coming. When a property accepts pipeline input <em>ByValue<\/em> then PowerShell will attempt to match the values passed to it and assign them accordingly. In this case <code>Stop-Process<\/code> only has the single property <em>-InputObject<\/em> that supports <em>ByValue<\/em> . Let us look a bit closer at how this works. <\/p>\n\n\n\n<p><code>Get-Process<\/code> is used to gather information and the output of that command is sent along the pipeline as input to the Stop-Process cmdlet. <code>Get-Process<\/code> has an output type of <em>System.Diagnostics.Process<\/em> and the <em>-InputObject<\/em> property of Stop-Process requires an input type of  <em>System.Diagnostics.Process<\/em>. How do we know this?Here we introduce another command you will come to rely on, it is <code>Get-Member<\/code>. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get-Member<\/h2>\n\n\n\n<p>You can also use the alias <code>gm<\/code>. If we pipe a fully formed cmdlet into <code>Get-Member<\/code> we then get an output similar to the screen capture below (NOTE: this has been concatenated for ease of reading). You can see all the parameters, attributes and lots of other information a command requires or produces using this command.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1157\" height=\"609\" src=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-2.png\" alt=\"\" class=\"wp-image-1004\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-2.png 1157w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-2-1000x526.png 1000w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-2-768x404.png 768w\" sizes=\"auto, (max-width: 1157px) 100vw, 1157px\" \/><figcaption>Screen capture showing an excerpt of the get-Member command for Get-Process<\/figcaption><\/figure>\n\n\n\n<p>As you can see here, we have a list of members of various types from aliases, events, methods and properties&#8230; cut of from this output is also a MemberType named ScriptProperty&#8230; what we are most interested in for this tutorial though is the very first line of output that shows the TypeName is <em>System.Diagnostics.Process<\/em> &#8211; this is the object type output.<\/p>\n\n\n\n<p>So now we know what the output type is and what we will be passing along the pipeline, it will be output of type  <em>System.Diagnostics.Process<\/em> <\/p>\n\n\n\n<p>Will Stop-Process accept this? Lets look again at the output of the Get-Help we ran earlier for Stop-Process<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"286\" src=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-3.png\" alt=\"\" class=\"wp-image-1005\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-3.png 822w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-3-768x267.png 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/figure>\n\n\n\n<p>Note the highlight this time shows the property <em>-InputObject<\/em> and as this is a property that accepts pipeline input, the type next to it is the type of input it requires, in our case <em>System.Diagnostics.Process<\/em>. The [ ] indicate it will accept an array of that type if necessary.<\/p>\n\n\n\n<p>So we have established that the output of <code>Get-Proces<\/code>s is  <em>System.Diagnostics.Process<\/em> and that <code>Stop-Process<\/code> can accept that as input through <em>-InputObject<\/em> how does it know to assign it to that? Well that comes down to the <em>ByValue<\/em> input. <\/p>\n\n\n\n<p>Powershell will attempt to assign the output of the command to an input of the next command, it will attempt to do it by Value. The first parametr that accepts input of the type <em>System.Diagnostics.Process<\/em> will be the one that gets the input of that type. In our case it is the ONLY one that accepts it and the only one that accepts input <em>ByValue<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ByPropertyName<\/h2>\n\n\n\n<p>If PowerShell cannot assign pipeline input <em>ByValue<\/em> it will attempt to do so by <em>ByPropertyName<\/em>. <\/p>\n\n\n\n<p>PowerShell will attempt to match a property of the object passed to a parameter of the command. This match occurs in its simplest form, if the object has a property &#8220;Id&#8221; it will be matched with the parameter &#8220;Id&#8221; because they are spelled the same. This can lead to unexpected results, especially with more common properties and parameters such as &#8220;Name&#8221;.<\/p>\n\n\n\n<p>Consider this:<\/p>\n\n\n\n<p>Your aim is to stop running processes but in error you type:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>get-service | stop-process<\/code><\/pre>\n\n\n\n<p><code>get-service<\/code> does not have any output of type <em>System.Diagnostics.Process<\/em> so assigning <em>ByValue<\/em> won&#8217;t work, however it does have a property with an alias of Name, so PowerShell will attempt to assign that <em>ByPropertyName<\/em><\/p>\n\n\n\n<p>On Windows 10 you could try this example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>get-service XblAuthManager | Stop-Process<\/code><\/pre>\n\n\n\n<p>The output you get should be an error, but the error comes from the Stop-Process command because it cant find a process named  <code>XblAuthManager<\/code> <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"108\" src=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-4.png\" alt=\"\" class=\"wp-image-1006\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-4.png 895w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/12\/image-4-768x93.png 768w\" sizes=\"auto, (max-width: 895px) 100vw, 895px\" \/><\/figure>\n\n\n\n<p>Whilst not perfectly clear, it does demonstrate that PowerShell has matched the name from Get-Service with the Name in Stop-Process and so <code>Stop-Process<\/code> has attempted to stop a process named XblAuthManager but failed because there wes no such process.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous section we looked at piping output to another command, we used it mainly to format the output of a command but we also looked briefly at how we might take an action based on the output by using the command Get-Process -ProcessName \u2018Notepad\u2019 | stop-process This gets the process ID for the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","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":[81,11],"class_list":["post-999","post","type-post","status-publish","format-standard","hentry","category-powershell","category-training","tag-powershell","tag-training","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pahuGk-g7","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/999","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=999"}],"version-history":[{"count":9,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/999\/revisions"}],"predecessor-version":[{"id":1063,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/999\/revisions\/1063"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}