Skip to content

Commit

Permalink
Merge pull request #2 from sirredbeard/docker-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sirredbeard authored Jun 3, 2023
2 parents 4f635f4 + 8f1b53c commit 786c858
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions list-wsl.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
$defaultGuid = (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss").DefaultDistribution

$wslDistributions = Get-ChildItem -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss" | ForEach-Object {
$distribution = @{
Name = ""
"Linux Distro" = ""
"Distro Version" = ""
systemd = ""
"Default User" = ""
State = ""
WSL = ""
}

$distribution = @{}
$distribution["Name"] = $_.GetValue("DistributionName")

$osRelease = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/os-release"
if ($osRelease) {
$distribution["Linux Distro"] = ($osRelease | Where-Object { $_ -like "PRETTY_NAME=*" }).Split("=")[1].Replace('"', '')
$distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "VERSION=*" }).Split("=")[1].Replace('"', '')
}

$wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf"
if ($wslConf) {
$distribution["systemd"] = ($wslConf | Where-Object { $_ -like "systemd=true" }).Count -gt 0
}

$distribution["DefaultUid"] = $_.GetValue("DefaultUid")

$username = Invoke-Command -ScriptBlock { wsl.exe -d $($distribution["Name"]) -- id -un -- $args[0] } -ArgumentList $distribution["DefaultUid"] -ErrorAction SilentlyContinue
if ($username) {
$distribution["Default User"] = $username
}

$distribution["State"] = $_.GetValue("State")
switch ($distribution["State"]) {
0x1 { $distribution["State"] = "Installed" }
0x3 { $distribution["State"] = "Installing" }
0x4 { $distribution["State"] = "Uninstalling" }
}

$distribution["WSL"] = $_.GetValue("Version")

if ($defaultGuid -eq $_.PSChildName) {
$distribution["Name"] += "*"
if ($distribution["Name"] -eq "docker-desktop") { $distribution["Linux Distro"] = "Docker Desktop"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" }
if ($distribution["Name"] -eq "docker-desktop-data") { $distribution["Linux Distro"] = "Docker Desktop Data"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" }
if ($distribution["Name"] -eq "docker-desktop-runtime") { $distribution["Linux Distro"] = "Docker Desktop Runtime"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" }

if ($distribution["Name"] -ne "docker-desktop" -and $distribution["Name"] -ne "docker-desktop-data" -and $distribution["Name"] -ne "docker-desktop-runtime") {
$osRelease = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/os-release"
if ($osRelease) {
$distribution["Linux Distro"] = ($osRelease | Where-Object { $_ -like "PRETTY_NAME=*" }).Split("=")[1].Replace('"', '')
$distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "*VERSION=*" }).Split("=")[1].Replace('"', '')
}

$wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf 2> `$null"
if ($wslConf -and $wslConf.Contains("systemd=true")) {
$distribution["systemd"] = "Enabled"
} else {
$distribution["systemd"] = "Disabled"
}

$distribution["DefaultUid"] = $_.GetValue("DefaultUid")

$username = Invoke-Command -ScriptBlock { wsl.exe -d $($distribution["Name"]) -- id -un -- $args[0] } -ArgumentList $distribution["DefaultUid"] -ErrorAction SilentlyContinue
if ($username) {
$distribution["Default User"] = $username
}

$distribution["State"] = $_.GetValue("State")
switch ($distribution["State"]) {
0x1 { $distribution["State"] = "Installed" }
0x3 { $distribution["State"] = "Installing" }
0x4 { $distribution["State"] = "Uninstalling" }
}

$distribution["WSL"] = $_.GetValue("Version")

if ($defaultGuid -eq $_.PSChildName) {
$distribution["Name"] += "*"
}
}

New-Object -TypeName PSObject -Property $distribution
Expand Down

0 comments on commit 786c858

Please sign in to comment.