-
Notifications
You must be signed in to change notification settings - Fork 13
/
New-LocationMarkdown.ps1
70 lines (56 loc) · 1.98 KB
/
New-LocationMarkdown.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
70
#requires -version 5.0
# generate a version of the user groups as a list in Markdown
# grouped by country and state
<#
This script will create a markdown version of PowerShell user groups
based on the json entries in the Data folder.
#>
[cmdletbinding(SupportsShouldProcess)]
Param(
[ValidateNotNullOrEmpty()]
[ValidatePattern("\.md$")]
[string]$OutputFile = "PowerShellGroupsbyLocation.md",
#the path to the folder with json data files
[string]$Path = ".\data",
[switch]$Passthru
)
$grouped = &$PSScriptRoot\get-uglist.ps1 -Path $path |
Sort-Object -property Country, State, Name |
Group-object -Property Country
$md = @"
# PowerShell Groups by Location
"@
foreach ($item in $Grouped) {
#strip off {} for country values with multiple entries like Australia,New Zealand
$name = $item.name -replace "{|}", ""
Write-Verbose "Processing $name"
$md += "`n## $name`n"
#group each user group by state
$states = $item.group | Group-Object -Property State
foreach ($state in $states) {
if ($state.name -match "\w+") {
write-Verbose "Adding $($state.name)"
$md += "`n### $($state.name)`n"
}
foreach ($group in $state.group) {
write-Verbose $group.name
$group.psobject.properties.name |
foreach-object {
if ($group.$_ -is [array]) {
$group.$_ = $group.$_ -join ","
}
}
$details = ($group | Select-Object -property Name, Owner, Location, WebSiteURL, Twitter, Email | Out-String).trim() -split "`n"
foreach ($detail in $details) {
$md += "`n$($detail.trim()) "
}
$md += "`n"
} #foreach state group
} #foreach group
}
$utc = &$PSScriptRoot\get-utc.ps1
$md += "`n_Generated $($utc)_"
$md | Out-File "$PSScriptRoot\$OutputFile" -Encoding utf8 -Width 80
if ($Passthru) {
Get-Item -Path "$psscriptroot\$OutputFile"
}