Created
September 28, 2016 18:31
-
-
Save bgelens/b82b991d461439af190e65b732555706 to your computer and use it in GitHub Desktop.
Parse os-release into object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-OSInfo { | |
[cmdletbinding(DefaultParameterSetName='Brief')] | |
param ( | |
[Parameter(ParameterSetName='Full')] | |
[Switch] $Full | |
) | |
process { | |
$osInfoFull = (Get-Content -Path /etc/os-release).Replace('"','') | ConvertFrom-StringData | |
if ($PSCmdlet.ParameterSetName -eq 'Brief') { | |
$osInfoFull.PRETTY_NAME | |
} else { | |
$osInfoFull | |
} | |
} | |
} | |
Get-OSInfo | |
>> Ubuntu 16.04.1 LTS | |
Get-OSInfo -Full | |
>> Name Value | |
>> ---- ----- | |
>> NAME Ubuntu | |
>> VERSION 16.04.1 LTS (Xenial Xerus) | |
>> ID ubuntu | |
>> ID_LIKE debian | |
>> PRETTY_NAME Ubuntu 16.04.1 LTS | |
>> VERSION_ID 16.04 | |
>> HOME_URL http://www.ubuntu.com/ | |
>> SUPPORT_URL http://help.ubuntu.com/ | |
>> BUG_REPORT_URL http://bugs.launchpad.net/ubuntu/ | |
>> UBUNTU_CODENAME xenial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment