Skip to content

Instantly share code, notes, and snippets.

@bgelens
Created September 28, 2016 18:31
Show Gist options
  • Save bgelens/b82b991d461439af190e65b732555706 to your computer and use it in GitHub Desktop.
Save bgelens/b82b991d461439af190e65b732555706 to your computer and use it in GitHub Desktop.
Parse os-release into object
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