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