{"id":78,"date":"2016-08-19T00:23:09","date_gmt":"2016-08-19T06:23:09","guid":{"rendered":"http:\/\/draith.com\/?p=78"},"modified":"2016-08-19T00:23:09","modified_gmt":"2016-08-19T06:23:09","slug":"powershell-on-linux-try-it-out-fast","status":"publish","type":"post","link":"http:\/\/draith.com\/?p=78","title":{"rendered":"PowerShell on Linux &#8211; Try it Out Fast!"},"content":{"rendered":"<p>Unless you have been living under a rock, you probably heard that Microsoft <a href=\"https:\/\/azure.microsoft.com\/en-us\/blog\/powershell-is-open-sourced-and-is-available-on-linux\/\">Open-Sourced PowerShell and made it available on Linux\/MacOS!<\/a>. Everyone wants to give this thing a try. Want to test it out quick? Here&#8217;s how:<\/p>\n<p>Versions used in this example:<br \/>\nWindows 10 Build 10586.545 (Hyper-V Host)<br \/>\n<a href=\"https:\/\/www.centos.org\/download\/\">CentOS 7<\/a><br \/>\n<a href=\"https:\/\/winscp.net\/eng\/download.php\">WinSCP 5.9.1<\/a><\/p>\n<p>A quick assumption (I know &#8211; we all know what happens when we assume) &#8211; You already have Hyper-V up and running. If not, read this post by <a href=\"https:\/\/twitter.com\/adbertram\">@adbertram<\/a> about <a href=\"http:\/\/www.tomsitpro.com\/articles\/hyper-v-powershell-cmdlets,2-779.html\">Essential PowerShell Cmdlets For Managing Hyper-V<\/a>. It&#8217;s a really well put together article.<\/p>\n<p>Start by downloading CentOS. The link above will take you to the download page &#8211; in this example I will use the DVD ISO. Since the <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\">PowerShell repo<\/a> is still in Alpha, I am going to stick with CentOS. Open Hyper-V Manager, and create a new VM. Do this by right-clicking on your computer in the tree pane, and selecting New &#8211; Virtual Machine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-80\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/new-virtualmachine-300x221.jpg\" alt=\"new-virtualmachine\" width=\"600\" height=\"442\" srcset=\"\/wp-content\/uploads\/2016\/08\/new-virtualmachine-300x221.jpg 300w, \/wp-content\/uploads\/2016\/08\/new-virtualmachine.jpg 575w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Click through the wizard, choosing a VM name, the generation (I used 2 for this demo), memory (8gb), the network (make sure it has internet access), where to store the VHD, and finally &#8211; under the installation options &#8211; select &#8220;Install an operating system from a bootable image file&#8221;.  Point it to the CentOS iso you downloaded previously.  Finish the wizard.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/vmsummary-300x227.jpg\" alt=\"vmsummary\" width=\"600\" height=\"454\" class=\"alignnone size-medium wp-image-82\" srcset=\"\/wp-content\/uploads\/2016\/08\/vmsummary-300x227.jpg 300w, \/wp-content\/uploads\/2016\/08\/vmsummary.jpg 701w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Before we start the VM we will need to disable Secure Boot, otherwise we won&#8217;t be able to load the DVD image.  Right click on the new VM, click Settings, Security, and uncheck the box for Secure Boot.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/secureboot-300x285.jpg\" alt=\"secureboot\" width=\"600\" height=\"570\" class=\"alignnone size-medium wp-image-84\" srcset=\"\/wp-content\/uploads\/2016\/08\/secureboot-300x285.jpg 300w, \/wp-content\/uploads\/2016\/08\/secureboot.jpg 721w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Start and connect to the VM.  When this menu appears, select &#8216;Install CentOS 7&#8243;.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/installcent-300x195.jpg\" alt=\"installcent\" width=\"600\" height=\"390\" class=\"alignnone size-medium wp-image-85\" srcset=\"\/wp-content\/uploads\/2016\/08\/installcent-300x195.jpg 300w, \/wp-content\/uploads\/2016\/08\/installcent-768x499.jpg 768w, \/wp-content\/uploads\/2016\/08\/installcent.jpg 1021w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Installing CentOS is pretty straight forward.  Select your language for setup, click Continue.  On the next screen, you are going to see the &#8220;Installation Summary&#8221; screen.  Here you will probably see some items marked with a classic warning symbol.  In my demo, it was the &#8220;Installation Destination&#8221; section.  Simply going into that section and selecting done is enough to clear it.  There is, however, one change we want to make before starting the installation.  Click on the &#8220;Network &#038; Host Name&#8221; section, set the hostname, and turn on eth0.  We need this vm to be able to access the internet, which is difficult without an active network adapter.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/network2-300x218.jpg\" alt=\"network2\" width=\"600\" height=\"436\" class=\"alignnone size-medium wp-image-88\" srcset=\"\/wp-content\/uploads\/2016\/08\/network2-300x218.jpg 300w, \/wp-content\/uploads\/2016\/08\/network2-1024x745.jpg 1024w, \/wp-content\/uploads\/2016\/08\/network2-768x558.jpg 768w, \/wp-content\/uploads\/2016\/08\/network2.jpg 1136w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Click Begin Installation.  The install will begin to run, and during this time you should go ahead and set the root password, and create a non-root user (not required, but a good idea anyway).  Setup doesn&#8217;t take long, so in a few minutes we are presented &#8220;Complete!&#8221; message.  Click the Reboot button.<\/p>\n<p>Within a minute or two, you should be presented with a CentOS Linux 7 login.  Go ahead and log in with root.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/rootlogin-300x105.jpg\" alt=\"rootlogin\" width=\"600\" height=\"210\" class=\"alignnone size-medium wp-image-87\" srcset=\"\/wp-content\/uploads\/2016\/08\/rootlogin-300x105.jpg 300w, \/wp-content\/uploads\/2016\/08\/rootlogin.jpg 373w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>If you don&#8217;t already have it installed, download and install WinSCP.  We are going to need to get the RPM for PowerShell from Github, and move it to the CentOS VM.  For this demo, we can get the RPM <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/releases\/download\/v6.0.0-alpha.9\/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm\">here<\/a>.  Once we have the RPM downloaded, launch WinSCP and connect to the CentOS VM.  Depending on networking, it might be necessary to connect via IP address.  In order to get the IP in this minimal CentOS install, we are going to need to use &#8216;ip addr&#8217;.  Note the IP for eth0.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/ip-300x99.jpg\" alt=\"ip\" width=\"600\" height=\"198\" class=\"alignnone size-medium wp-image-90\" srcset=\"\/wp-content\/uploads\/2016\/08\/ip-300x99.jpg 300w, \/wp-content\/uploads\/2016\/08\/ip.jpg 729w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>In WinSCP, connect to the VM using root, and copy the rpm to the \/tmp directory.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/winscp-300x192.jpg\" alt=\"winscp\" width=\"600\" height=\"394\" class=\"alignnone size-medium wp-image-91\" \/><\/p>\n<p>Now the fun begins.  Go back to the CentOS VM, and run the following command:<\/p>\n<pre class=\"lang:batch decode:true \" >sudo yum -y install \/tmp\/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm<\/pre>\n<p>This command tells the VM to install the PowerShell rpm we downloaded, and the &#8216;-y&#8217; tells it to automatically install the 2 dependencies.  When it&#8217;s done, you are rewarded with something like this<br \/>\n<img decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/powershellinstalled-300x225.jpg\" alt=\"powershellinstalled\" width=\"600\" height=\"120.\" class=\"alignnone size-medium wp-image-93\" srcset=\"\/wp-content\/uploads\/2016\/08\/powershellinstalled-300x225.jpg 300w, \/wp-content\/uploads\/2016\/08\/powershellinstalled-1024x768.jpg 1024w, \/wp-content\/uploads\/2016\/08\/powershellinstalled-768x576.jpg 768w, \/wp-content\/uploads\/2016\/08\/powershellinstalled.jpg 1154w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>Once this is done &#8211; we have PowerShell on this CentOS VM.  That is not something I thought I would type anytime soon \ud83d\ude42  Why don&#8217;t we see if it works.  It&#8217;s basically another shell, so let&#8217;s start by typing &#8216;powershell&#8217;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/psprompt-300x53.jpg\" alt=\"psprompt\" width=\"600\" height=\"106\" class=\"alignnone size-medium wp-image-94\" srcset=\"\/wp-content\/uploads\/2016\/08\/psprompt-300x53.jpg 300w, \/wp-content\/uploads\/2016\/08\/psprompt.jpg 550w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>Take a moment to look at this &#8211; a Microsoft PowerShell prompt, running in a Linux VM.  Want proof?  Do a get-service, but look for something uniquely *nix.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/draith.com\/wp-content\/uploads\/2016\/08\/get-process-300x73.jpg\" alt=\"get-process\" width=\"600\" height=\"146\" class=\"alignnone size-medium wp-image-95\" srcset=\"\/wp-content\/uploads\/2016\/08\/get-process-300x73.jpg 300w, \/wp-content\/uploads\/2016\/08\/get-process.jpg 635w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>And there you go.  Microsoft dropped the mic in a big way on this one.  VERY well done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unless you have been living under a rock, you probably heard that Microsoft Open-Sourced PowerShell and made it available on Linux\/MacOS!. Everyone wants to give this thing a try. Want to test it out quick? Here&#8217;s how: Versions used in this example: Windows 10 Build 10586.545 (Hyper-V Host) CentOS 7 WinSCP 5.9.1 A quick assumption &hellip; <a href=\"http:\/\/draith.com\/?p=78\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;PowerShell on Linux &#8211; Try it Out Fast!&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9,11,16],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-hyper-v","tag-linux","tag-powershell"],"_links":{"self":[{"href":"http:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":0,"href":"http:\/\/draith.com\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"wp:attachment":[{"href":"http:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/draith.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}