From 6a0bd12e54ffc8e03ffe242bf4b5298bc8df0a9a Mon Sep 17 00:00:00 2001 From: corbob Date: Mon, 23 Nov 2020 19:59:11 -0800 Subject: [PATCH] (#13) Add All switch all will do agrant global-status while regular will now do agrant status --- public/Get-VagrantEnvironment.ps1 | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/public/Get-VagrantEnvironment.ps1 b/public/Get-VagrantEnvironment.ps1 index bfd9969..b721c1c 100644 --- a/public/Get-VagrantEnvironment.ps1 +++ b/public/Get-VagrantEnvironment.ps1 @@ -16,18 +16,24 @@ function Get-VagrantEnvironment { #> [cmdletBinding()] - Param() + Param( + [switch] + $All + ) process { - - $environments = vagrant global-status - - $environments = $environments[2..$($environments.Length-8)] - + $command = 'status' + $extraLines = 4 + if($All){ + $command = 'global-status' + $extraLines = 8 + } + $environments = & vagrant $command + $environments = $environments[2..$($environments.Length - $extraLines)] Foreach($environment in $environments){ + # This is global-status environments if($environment -match "^(?[\w]+)\s+(?[\w\-._]+)\s+(?[\w]+)\s+(?[\w]+)\s+(?[\/\-\w:]+)"){ - [pscustomobject]@{ Id = $matches.id Name = $matches.name @@ -37,9 +43,17 @@ function Get-VagrantEnvironment { } } + # This is status environments + if($environment -match "^(?[\w\-._]+)\s+(?[\w]+)\s+\((?[\w]+)\)"){ + [pscustomobject]@{ + Name = $matches.name + Provider = $matches.provider + State = $matches.state + } + + } } - } -} \ No newline at end of file +}