![]() Please see Dave F's comment I wrote this answer because that seems how SO works to get an answer promoted from a comment. See PlatformID documentation for details. This works in all versions of PowerShell as this has been available from. ![]() New-Variable -Option Constant -Name IsMacOs -Value $false -ErrorAction Silentl圜ontinue New-Variable -Option Constant -Name IsLinux -Value $false -ErrorAction Silentl圜ontinue New-Variable -Option Constant -Name IsWindows -Value $True -ErrorAction Silentl圜ontinue With the advent of PowerShell 7 and it’s cross-platform ability, the idea of using PowerShell to manage Linux systems becomes more attractive. ![]() Here's what I have in my profile.ps1 to make this easier by setting $IsWindows: function Get-PSPlatform If it returns Unix then you're obviously running v6 , so further information can be had from $PSVersionTable.PSEdition, $PSVersionTable.Platform, and $PSVersionTable.OS, and the automatic variables will be available too: $IsLinux, $IsMacOs, and $IsWindows. This will return either Win32NT for anything descended from Windows NT (all current versions of Windows) or Unix for anything *nix (including Mac, Linux,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |