{"id":967,"date":"2021-08-03T12:53:30","date_gmt":"2021-08-03T11:53:30","guid":{"rendered":"http:\/\/vroamam.com\/wordpress\/?p=967"},"modified":"2021-08-14T13:47:05","modified_gmt":"2021-08-14T12:47:05","slug":"introducing-the-pipeline","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/introducing-the-pipeline\/","title":{"rendered":"Introducing the Pipeline"},"content":{"rendered":"\n<p>The pipeline is a feature that allows the output of one command to be automatically transferred into another command. You can string any number of commands together and they will execute sequentially left to right. when it reaches the last command the results of this will be displayed on the screen or passed to a variable.<\/p>\n\n\n\n<p>The simplest use of the pipleine is to format the output as a list or table<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-Service | Format-List\nGet-Service | Format-Table<\/pre>\n\n\n\n<p>You may see these shorterned to their alias <code>fl <\/code>or <code>ft<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><meta charset=\"utf-8\">Get-Service | ft \nGet-Service | fl<\/pre>\n\n\n\n<p>What this series of commands is doing is getting all services on the local machine and then formatting them into either a list or table. From left to right <code>get-service<\/code> then take the output and <code>format-list<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using the pipeline<\/h2>\n\n\n\n<p>We can use the pipeline to automate tasks without knowing the list of items we need to change<\/p>\n\n\n\n<p>Let&#8217;s consider a list of processes, we can find all running processes with a get command but which one? Lets use <code>Get-Command <\/code>to find it<\/p>\n\n\n\n<p><code>Get-Command *process*<\/code> returns a list of cmdlets we can use against processes, we can find them with <code>Get-Process<\/code>, stop them with <code>Stop-Process<\/code> and start them with <code>Start-Process<\/code><\/p>\n\n\n\n<p>We have a number of Notepad instances open on our machine and we want to stop the processes, how can we do that in one command? Lets start by finding all the running processes. I&#8217;ll start by looking at the syntax of the cmdlet using the help<\/p>\n\n\n\n<p>we can see in the output of the Get-Process cmdlet that there is a column called processName so lets start with that can we list only the ones named &#8216;Notepad&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-Process -ProcessName 'Notepad'<\/pre>\n\n\n\n<p>It appears we can<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"117\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-9.png\" alt=\"\" class=\"wp-image-972\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-9.png 812w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/08\/image-9-768x111.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p>now using the pipeline we can send this output to the stop-process command<\/p>\n\n\n\n<p><meta charset=\"utf-8\">Get-Process -ProcessName &#8216;Notepad&#8217; | stop-process<\/p>\n\n\n\n<p>This stops all running processes with the ProcessName &#8216;notepad&#8217; &#8211; we can confirm this has worked by re-runnign the <code>Get-Process<\/code> command and checking their are none running<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Other Uses<\/h2>\n\n\n\n<p>Other common commands we will pipe into frequently that we will look at in other posts<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>Sort-Object<\/code> (alias <code>sort<\/code>)<\/li><li><code>Where-Object<\/code> (alias <code>where<\/code>)<\/li><li><code>Filter-Object<\/code> (alias <code>filter<\/code>)<\/li><li><code>Group-Object <\/code>(alias <code>group<\/code>)<\/li><li><code>Format-Table<\/code> (alias <code>ft<\/code>)<\/li><li><code>Format-List<\/code> (alias <code>fl<\/code>)<\/li><li><code>Select-Object <\/code>(alias <code>select<\/code>)<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The pipeline is a feature that allows the output of one command to be automatically transferred into another command. You can string any number of commands together and they will execute sequentially left to right. when it reaches the last command the results of this will be displayed on the screen or passed to a [&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":"","ocean_second_sidebar":"","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":"","ocean_custom_header_template":"","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":"","ocean_menu_typo_font_family":"","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":"","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":"on","ocean_gallery_id":[],"footnotes":""},"categories":[114,3],"tags":[81,11],"class_list":["post-967","post","type-post","status-publish","format-standard","hentry","category-powershell","category-training","tag-powershell","tag-training","entry"],"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/967","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=967"}],"version-history":[{"count":1,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/967\/revisions"}],"predecessor-version":[{"id":973,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/967\/revisions\/973"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}