Skip to content

Commit e08652f

Browse files
author
Andrew
committed
Feedback 1
1 parent d782a50 commit e08652f

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

resources/Microsoft.DSC.Experimental/0.0.1/Microsoft.DSC.Experimental.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ VariablesToExport = @()
3434
AliasesToExport = @()
3535

3636
# DSC resources to export from this module
37-
DscResourcesToExport = 'Service'
37+
DscResourcesToExport = 'SystemctlService'
3838

3939
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
4040
PrivateData = @{

resources/Microsoft.DSC.Experimental/0.0.1/Microsoft.DSC.Experimental.psm1

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using namespace System.Collections.Generic
55

66
[DscResource()]
7-
class Service
7+
class SystemctlService
88
{
99
[DscProperty(Key)]
1010
[string] $Unit
@@ -30,46 +30,34 @@ class Service
3030
return $false
3131
}
3232

33-
[Service] Get()
33+
[SystemctlService] Get()
3434
{
3535

36-
return [Service]::GetServices() | ? {$_.Unit -eq $this.Unit }
36+
return [SystemctlService]::GetAll() | Where-Object {$_.Unit -eq $this.Unit }
3737
}
3838

39-
static [Service[]] Export()
39+
static [SystemctlService[]] Export()
4040
{
41-
$resultList = [List[Service]]::new()
42-
$svcs = [Service]::GetServices()
43-
$svcs | %{
44-
$obj = New-Object Service
45-
$obj.Unit = $_.Unit
46-
$obj.Load = $_.Load
47-
$obj.Active = $_.Active
48-
$obj.Sub = $_.Sub
49-
$obj.Description = $_.Description
50-
51-
$resultList.Add($obj)
52-
}
53-
54-
return $resultList.ToArray()
41+
return [SystemctlService]::GetAll()
5542
}
5643

57-
static [pscustomobject[]] GetServices()
44+
static [SystemctlService[]] GetAll()
5845
{
5946
$out = systemctl -l --type service --all
60-
$resultList = [List[pscustomobject]]::new()
47+
$resultList = [List[SystemctlService]]::new()
6148
$out | select-object -skip 1 | select-object -skiplast 7 | %{
6249
$arr = $_.split(" ", [System.StringSplitOptions]::RemoveEmptyEntries)
50+
51+
if ($arr[2] -ne 'not-found') {
52+
$obj = New-Object SystemctlService
53+
$obj.Unit = $arr[0]
54+
$obj.Load = $arr[1]
55+
$obj.Active = $arr[2]
56+
$obj.Sub = $arr[3]
57+
$obj.Description = ($arr | select-object -last ($arr.Count - 4)) -join " "
6358

64-
$a = [pscustomobject]@{
65-
Unit = $arr[0]
66-
Load = $arr[1]
67-
Active = $arr[2]
68-
Sub = $arr[3]
69-
Description = ($arr | select-object -last ($arr.Count - 4)) -join " "
59+
$resultList.Add($obj)
7060
}
71-
72-
if ($a.active -ne 'not-found') { $resultList.Add($a)}
7361
}
7462
return $resultList.ToArray()
7563
}

0 commit comments

Comments
 (0)