Recently Microsoft announced that PowerShell has been open sourced, and made generally available on Linux and Mac Os X. It is currently (04.11.2016) in alpha version available on github. I happen to have a Mac Book Pro available at home. And was pretty curious of what powershell mac os x would actually really be like. In this blog post I will walk you through the very beginning of using powershell Mac Os x. How does PowerShell Mac os X works? How to install powershell mac os x? what works currently on Powershell Mac Os x? What doesn’t work on Powershell Mac Os X? Where do we download powershell mac os x? etc… All of these first questions you have to start with powershell on Mac os x will be answered in this blog post.
PowerShell, became my bridge to discovering new platforms
I have to admit, that I am a SUPER Mac Noob. This means, that I have barely touched a Mac in my life. I have been a Windows Focused person for as long as I can remember. The good thing about PowerShell getting open sourced is that it draw a bridge for me to new platforms to work with, which I would normally never even think of touching.
I am not sure if any other ‘windows’ focused users like me have been tempting in seeing by how Powershell works on a Mac os x. Just in case, I detailed all the steps, since they were totally new for me.
The latest version is PowerShell 6.0 Alpha 13. I have updated all the links in the post to the latest version. See below for the download link, and read at the bottom of this article what the latest version brought to the game.
->22/11/2016: Version 6.0 Alpha 13 is released.
->02/11/2016: Version 6.0 Alpha 12 is released.
-> 18/10/2016: An update to the PowerShell Core package came out (18/10/2016).
How to install powershell on mac os x?
Since I update this post at each new release, the Screenshots in this article might indicate old version numbers, but the operations to install etc…are still valid. All links are updated to always point to the latest powershell for OS x version. (If you find a missing link, please let me know in the comment section).
First things first, you will need to download the pkg file on the official powershell github page here.
Once downloaded, we can either open a terminal, and launch the installation of powershell mac os x as followed:
sudo installer -pkg powershell-6.0.0-alpha.13.pkg -target /
as explained in the install instructions here.
Or you can simply double click the powershell mac os x .pkg like I did. Of course, having my beginner noob karma, I have bounced in the following errer message:
powershell-6-0-0-alpha.12.pkg can’t be opened because it from an unidentified developer.
After some researches (and quite a few failed attempts to try to do a right click…) I found where I could fix this. You will have to go to “system” – “Security & Privacy” and then click on “Click on the lock to unlock” (it took me a short while to actually realize that that image was ‘clickable’).
Another way of doing it is pointed out by “Joe” in the comments:
‘Instead of disabling the system security, you can Ctrl+Click the .PKG and click Open to bypass the unknown developer lockout. This works with .APPs by the way and only needs to be done once.’
What is cool about this, is that OS X will remember this, and make it a standard behaviour for any double click in the futur.
Thanks again to Joe for this feedback!
The installation will then start, and will be pretty similar to a windows installation process.
You will need to provide credentials that has administrative priviledges to install powershell mac os x.
And after a short while, it will be installed.
Now that powershell was installed, you can directly open a terminal and write “powershell” to launch the powershell process in Terminal. The first thing to check is the $psversiontable to see on which version we are currently working on.
I was also very curious about the amount of cmdlets that have been made available in powershell mac os x. we can see that a total of 345 cmdlets have been shipped in the alpha version (188.8.131.52) In the second part of the screen shot below.
Detailed information on which cmdlets have been shipped, which cmdlets are currently working, which ones have been reported as having issues can be found here.
The next step what to see the amount of modules. I was surprised that only 4 were available on my system as showed in the screenshot below.
Accessing Mac OS X system information using PowerShell
The next step was I wanted to know what version of Mac Os X I was running on, and was trying to find an equivalent to the win32_operatingsystem CIM class (or something that could provide me the same information) of my system. I quickly found about “system_profiler” on mac os x, and soon after that wrote the following powershell function that will return mac os x system information from within a powershell console.
Powershell core comes with the following four automatic variables:
Their purpose is pretty self explanatory. These automatic variables will definitely be very useful in the future to identify on which type of system we are executing the powershell.
Powershell mac os x: working with the file system
The last test I did was to use some existing powershell knowledge, and to see how that would work in a powershell terminal on mac os x. I have created all these screen shots on the desktop of my Mac Os x, I needed to move them in a subfolder to keep my desktop clean and tidy: Sounds like the perfect real first powershell task on my mac os x.
PowerShell is normally –on windows systems– not case sensitive. But in PowerShell core – On mac os x and linux – powershell os x is case sensitive.
I simply copied over the pictures from my desktop to the pictures folder.
Latest improvements in PowerShell core
As explained previously, PowerShell core is the version of powershell that is opened sourced and made available for mac os x. Find here under the improvements added to the latest versions.
- Fix Get-ChildItem -Recurse -ErrorAction Ignore to ignore additional errors
- Don’t block pipeline when running Windows exes
- Fix for PowerShell SSH remoting with recent Win32-OpenSSH change.
- Select-Object with -ExcludeProperty now implies
-Property *if -Property is not specified.
- Adding ValidateNotNullOrEmpty to -Name parameter of Get-Alias
- Enable Implicit remoting commands in PowerShell Core
- Fix GetParentProcess() to replace an expensive WMI query with Win32 API calls
- Fix Set-Content failure to create a file in PSDrive under certain conditions.
- Adding ValidateNotNullOrEmpty to -Name parameter of Get-Service
- Adding support in Get-WinEvent -FilterHashtable
- Adding WindowsVersion to Get-ComputerInfo
- Remove the unnecessary use of lock in PseudoParameterBinder to avoid deadlock
- Refactor Get-WinEvent to use StringBuilder for XPath query construction
- Clean up and fix error handling of libpsl-native
- Exclude Registry and Certificate providers from UNIX PS
- Update PowerShell Core to consume DotNet Core preview1-24530-04
- Add ‘-Title’ to ‘Get-Credential’ and unify the prompt experience
- Update dependency list for PowerShell Core on Linux and OS X
- Fix ‘powershell -Command -‘ to not hang and to not ignore the last command
- Fix binary operator tab completion
- Enable ‘ConvertTo-Html’ in PowerShell Core
- Remove most Maximum* capacity variables
- Fix ‘Get-ChildItem -Hidden’ to work on system hidden files on Windows
- Fix ‘JsonConfigFileAccessor’ to handle corrupted ‘PowerShellProperties.json’ and defer creating the user setting directory until a write request comes
- Fix variable assignment to not overwrite readonly variables
- Fix ‘Get-WinEvent -FilterHashtable’ to work with named fields in UserData of event logs
- Fix ‘Get-Help -Online’ in PowerShell Core on Windows
- Spelling/grammar fixes
- Fix passing escaped double quoted spaces to native executables
- Add Dockerfiles to build each Linux distribution
~/.config/PowerShellcapitalization bug fixed
- Fix crash on Windows 7
- Fix remote debugging on Windows client
- Fix multi-line input with redirected stdin
- Add PowerShell to
Install-Moduleversion comparison bug
- Spelling fixes
All releases can be found here.