{"id":749,"date":"2021-06-06T12:41:29","date_gmt":"2021-06-06T11:41:29","guid":{"rendered":"http:\/\/vroamam.com\/wordpress\/?p=749"},"modified":"2021-06-06T13:38:32","modified_gmt":"2021-06-06T12:38:32","slug":"aliases-modules-and-environment-variables","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/aliases-modules-and-environment-variables\/","title":{"rendered":"Aliases, Modules and Environment Variables"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Aliases<\/h2>\n\n\n\n<p>Command aliases will be well known by many Bash users, the practise of setting aliases for common commands is frequently discussed and aliases are shared.<\/p>\n\n\n\n<p>Just as the name suggests it is an alternate method of calling a command with its parameters using shortened or more meaningful text for example <code>alias sha='shasum -a 256'<\/code>. In this example we can now call the shasum command with its arguments to create a sha256 checksum just by using the command <code>sha<\/code><\/p>\n\n\n\n<p>We can do the same with PowerShell and it comes with some already built in. Some common ones allow the use of well know commands inside the command shell so we don&#8217;t have to learn new ones, common examples are <code>ls<\/code> and <code>dir<\/code> which are aliases for the PowerShell cmdlet <code>get-childitem<\/code><\/p>\n\n\n\n<p>If you want to see what Aliases you have set you can look at them all open PowerShell and type this<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Get-Alias<\/code><\/pre>\n\n\n\n<p>It will return a long list, this is just part of mine, you can see the output for dir highlighted in orange<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"546\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-4.png\" alt=\"\" class=\"wp-image-783\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-4.png 859w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-4-768x488.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p>if you only want to see what cmdlet an alias is for you can specify it on the command line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Get-Alias dir<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"100\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-5.png\" alt=\"\" class=\"wp-image-784\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-5.png 859w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-5-768x89.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p>If you want to set your own, you can use set-alias, why don&#8217;t you use the help commands you learned about in the previous article to see if you can set your own alias.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Modules<\/h2>\n\n\n\n<p>PowerShell come with some cmdlets that are just available as soon as you start the command shell. Good examples of these are <code>Get-Command and<\/code> <code>Get-Help<\/code>. PowerShell though can be use dot manage all sorts of Microsoft technologies including Exchange, Office 365 Azure et al. If every command was pre-installed the system would be enormous and incredibly slow and cumbersome, so like many other languages PowerShell stores collections of command together and you can import only the ones you need just when you need them.<\/p>\n\n\n\n<p>PowerShell calls these collection Modules. You have to install them and then import them.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Install-Module <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Import-Module<\/code><\/pre>\n\n\n\n<p>To see what you have available (Installed) and what you have imported use the cdmlets<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Get-Module -ListAvailable<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"411\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-2.png\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-2.png 859w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-2-768x367.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Get-Module<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"139\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-3.png\" alt=\"\" class=\"wp-image-782\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-3.png 859w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-3-768x124.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n\n\n\n<p>In PowerShell 5.1 Modules will auto import when you attempt to use a cmdlet they contain. They must already be installed and I am not clear in which version of PowerShell this behaviour wa first seen.<\/p>\n\n\n\n<p>We will look more at Modules, including making our own, in a future article.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Environment Variables<\/h2>\n\n\n\n<p>Everything in PowerShell is treated like a filesystem. We will revisit this concept later, but all parts of the OS such as the registry are available as drives,  if you want to view environment variable values the simplest way is to cd the the <code>env:<\/code> drive  <\/p>\n\n\n\n<p>You can now see all the environment variables by calling <code>Get-ChildItem<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"859\" height=\"394\" src=\"http:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-6.png\" alt=\"\" class=\"wp-image-787\" srcset=\"https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-6.png 859w, https:\/\/vroamam.com\/wordpress\/wp-content\/uploads\/2021\/06\/image-6-768x352.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>A brief tutorial on aliases, modules and how to read and set environment variables using PowerShell<\/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":"","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":"on","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":[117,119,118,81,11],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-powershell","category-training","tag-aliases","tag-environment-variables","tag-modules","tag-powershell","tag-training","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pahuGk-c5","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/749","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=749"}],"version-history":[{"count":26,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":793,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/749\/revisions\/793"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}