{"id":912,"date":"2021-06-12T10:45:37","date_gmt":"2021-06-12T09:45:37","guid":{"rendered":"http:\/\/vroamam.com\/wordpress\/?p=912"},"modified":"2021-08-14T13:47:34","modified_gmt":"2021-08-14T12:47:34","slug":"powershell-general-cmdlet-constructs","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/powershell-general-cmdlet-constructs\/","title":{"rendered":"PowerShell &#8211; General cmdlet constructs"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Cmdlet structure<\/h2>\n\n\n\n<p>And so to a discussion on cmdlet structure.<\/p>\n\n\n\n<p>PowerShell use a verb noun structure which may be followed by some parameters. Parameters are not compulsory as we saw in the help section but knowing how the commands maybe structured can help find the right one<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">verb-noun -parameter1 -parameter2<\/pre>\n\n\n\n<p>Common verbs in use<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Get<\/li><li>Set<\/li><li>Add<\/li><li>Remove<\/li><li>New<\/li><\/ul>\n\n\n\n<p>Common nouns would be for windows components for example<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Service<\/li><li>Process<\/li><li>EventLog<\/li><li>ChildItem<\/li><\/ul>\n\n\n\n<p>So the command to get information about the services on the local computer would be<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-Service<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"365\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-8.png\" alt=\"\" class=\"wp-image-917\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-8.png 805w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-8-768x348.png 768w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><figcaption>The output of Get-Service cmdlet<\/figcaption><\/figure>\n\n\n\n<p>To get information about an individual service you would add that as a parameter<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-Service -Name Spooler<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"97\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-10.png\" alt=\"\" class=\"wp-image-919\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-10.png 805w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-10-768x93.png 768w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><figcaption>The output of Get-Service cmdlet for the spooler service<\/figcaption><\/figure>\n\n\n\n<p>We can create things with verbs like <code>New<\/code> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"146\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-11.png\" alt=\"\" class=\"wp-image-920\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-11.png 805w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-11-768x139.png 768w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><\/figure>\n\n\n\n<p>and add content to them with verbs like <code>Add<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"146\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-12.png\" alt=\"\" class=\"wp-image-922\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-12.png 805w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-12-768x139.png 768w\" sizes=\"auto, (max-width: 805px) 100vw, 805px\" \/><\/figure>\n\n\n\n<p>Do you remember the <code>Get-Command<\/code> cmdlet we mentioned in the help post? You can use that to help you find things with a particular verb like this<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Get-Command get-*\nGet-Command Set-*\nGet-Command Add-*<\/pre>\n\n\n\n<p>If you wanted to narrow that down to a particular noun, you can just make the wildcard a but more specific<\/p>\n\n\n\n<pre id=\"block-7e12c705-6a0d-46f5-8a43-e4fb310ffa18\" class=\"wp-block-preformatted\">Get-Command get-*network*\nGet-Command Set-*network*\nGet-Command Add-*windows*<\/pre>\n\n\n\n<p>You&#8217;ll also see in the lists these commands produce whether they are and alias or a PowerShell cmdlet. Do you remember what an Alias is? If not go back and re-read <a rel=\"noreferrer noopener\" target=\"_blank\" href=\"http:\/\/vroamam.com\/wordpress\/blog\/aliases-modules-and-environment-variables\/\">this lesson<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>cmdlets are made up of a verb (action) and a noun (thing) and all we are doing is telling PowerShell to do something and what to do it on. Get something about, add something to, set something on &#8230; it is really that simple.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cmdlet structure And so to a discussion on cmdlet structure. PowerShell use a verb noun structure which may be followed by some parameters. Parameters are not compulsory as we saw in the help section but knowing how the commands maybe structured can help find the right one verb-noun -parameter1 -parameter2 Common verbs in use Get [&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-912","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\/912","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=912"}],"version-history":[{"count":11,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/912\/revisions"}],"predecessor-version":[{"id":930,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/912\/revisions\/930"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}