-
Notifications
You must be signed in to change notification settings - Fork 22
/
Get-DscResourceKitInfo.ps1
69 lines (60 loc) · 2 KB
/
Get-DscResourceKitInfo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#Requires -Module @{ ModuleName = 'PowerShellGet'; ModuleVersion = '2.1.3' }
function Get-DscResourceKitInfo
{
[CmdletBinding()]
param
(
[Parameter(
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[System.String[]]
$ResourceModule = (Get-Content -Raw -Path (Join-Path -Path $PSScriptRoot -ChildPath '\data\resources.json') | ConvertFrom-Json).Resources,
[Parameter()]
[System.String]
$ExportTo
)
begin
{
<#
Using [ordered] to make sure the modules are written to disk in
alphabetical order (see sorting further down). This is so that
it is easier to review.
#>
$allResources = [ordered] @{ }
}
process
{
# Sorting the resource modules so the resulting file is easier to review.
foreach ($resourceName in ($ResourceModule | Sort-Object))
{
try
{
Write-Verbose -Message ('Get information about module {0}.' -f $resourceName)
$moduleResourceInfo = Find-Module -Name $resourceName -ErrorAction 'Stop' -AllowPrerelease
if ($ModuleResourceInfo)
{
$allResources.Add($resourceName, $moduleResourceInfo)
}
}
catch
{
Write-Warning -Message ('Could not get information about resource module {0}. Error: {1}' -f $resourceName, $_.Exception.Message)
}
}
}
end
{
$moduleInformation = $allResources | ConvertTo-Json -Depth 12
if ($PSBoundParameters.ContainsKey('ExportTo'))
{
$utf8NoBomEncoding = New-Object -TypeName System.Text.UTF8Encoding -ArgumentList $false
[System.IO.File]::WriteAllLines($ExportTo, $moduleInformation, $utf8NoBomEncoding)
}
else
{
$moduleInformation
}
}
}
Get-DscResourceKitInfo -ExportTo './data/en/resources.json'