How to detect Linux or macOS or Windows in powershell?
NickName:SebMa Ask DateTime:2020-11-18T21:11:17

How to detect Linux or macOS or Windows in powershell?

I use uname -s in bash scripts to determine the OS and it returns Linux, Darwin or MINGW64_NT... when its running on Linux, macOS or Windows.

EDIT0 : I want my $PROFILE script to detect the OS whether is running on Windows with PS (version could be lower than 6) or Linux with PSv>=6.

I found this in powershell :

PS> [System.Environment]::OSVersion.Platform

On Linux, it returns Unix and on a 64bits Windows, it returns Win32NT.

I don't have a macOS at my disposal (not yet:)) so I don't know what it actually returns on macOS.

EDIT1 : This method doesn't seem to different between Unix and Linux or Windows32b and Windows64b.

What other ways are there to detect the OS in powershell 5.1 ?

Copyright Notice:Content Author:「SebMa」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/64893785/how-to-detect-linux-or-macos-or-windows-in-powershell

More about “How to detect Linux or macOS or Windows in powershell?” related questions

How to detect Linux or macOS or Windows in powershell?

I use uname -s in bash scripts to determine the OS and it returns Linux, Darwin or MINGW64_NT... when its running on Linux, macOS or Windows. EDIT0 : I want my $PROFILE script to detect the OS whet...

Show Detail

Detect Input IDLE on MacOS and Linux

It's need to port our software on MacOS and Linux. How can I detect input IDLE on MacOS and Linux using Delphi 10.2? In Windows I use : aLastInputInfo.cbSize := SizeOf(TLastInputInfo);

Show Detail

How to detect headset wire control in macos

In windows/linux, The headset wire control is the same as the keyboard event. However, I can't use CGEventSourceKeyState to detect headset wire control in macos.

Show Detail

How to Run Scripts in sudo/admin on flutter windows/linux/macos?

I've seen some solution on MacOS on showing a GUI prompt for running scripts in sudo dart / flutter run process with sudo But for Linux and Windows, I dont see any solution. I havent tested yet, bu...

Show Detail

How to Run Scripts in sudo/admin on flutter windows/linux/macos?

I've seen some solution on MacOS on showing a GUI prompt for running scripts in sudo dart / flutter run process with sudo But for Linux and Windows, I dont see any solution. I havent tested yet, bu...

Show Detail

How to detect heterogeneous CPU topologies on Linux?

Many recent CPUs out there--Alder Lake from Intel and many big.LITTLE designs from ARM--have heterogeneous CPU topologies: some cores are faster than others. There exists good ways to detect such ...

Show Detail

How can I detect USB serial port connections in C on Windows and macOS?

Using libudev in Linux I am able to add a handle to an event manger to detect on boot and upon plugging in a USB serial device by monitoring tty events. self->udev_monitor =

Show Detail

wxWidgets Windows->MacOS or Linux

I did a C++ code whose GUI is implemented with wxWidgets 3.1, and which I run on Windows. Being a cross-platform solution, I tried compiling the project on MacOS. I'm running into several issues:

Show Detail

Linux Powershell inserting into PostgreSQL

I'm not used to Powershell, so I'm sorry if this is a noob question. I would like to extract data from WSUS Windows Internal Database and insert it into a PostgreSQL running on Linux. I currently...

Show Detail

Detect if process executes inside a Windows Container

It's simple. I would like to detect with code if my process is running inside a windows container. There are examples but they are all for linux based containers. I'm looking for something unique...

Show Detail