How to get OSX and Linux system information using Powershell

Powershell is now on OSX and Linux systems and in beta. Pretty cool that version 6 is going to be able to be used on multiple platforms. But with that comes some issues with determining what kind of system you're on. There are now some global variables that help determine this, but lets check out the other ways.

There was a time when I was working with a module called PowerTrello, and I was refactoring the token request from trello's api. The original author had used IE to navigate to the url, have the user click 'login' and then gather the token from the location.

This approach doesn't work in OSX or Linux, for obvious reasons, so I had to find another way to just open the browser and pass it a location to go to. Efectively simulating the same experience accross platforms. (To be fair, I just used 'open' and gave it a url, so not 100% match )

It would have been a lot nicer to be able to determine what system I was on and then determine the proper way to access a browser this way.

So enough, talk what are the commands?

Well, on OSX we always have system_profiler:


However, it takes some time to run. And usually it gives you a bit too much. Try sw_vers:


You should see output like this:

Pass the value to our old pal Get-Member, and see that it's a string.

Well what if we don't want to have to run that, then parse it? What if we just want to get back a true/false?

Well, what if that actually is a thing? What if there were some global variables that tell you?

Get-Variable | Out-String

You should see an output like this:

See that highlighted section?


Pretty cool right?

Now, for that Request-TrelloAccessToken I was working on I can simply check what the system information is and then do the needful.