Code: Select all
param(
[Parameter()]
[string]$topicFile
)
# Check if topicFile exists
if (!(Test-Path $topicFile -PathType Leaf)) {
Write-Host "Document $topicFile in Topics does not exist" -ForegroundColor Red
Exit
}
function Snippets {
param (
[Parameter()]
$path,
[Parameter()]
$topicFile,
[Parameter()]
$depth
)
if (!(Test-Path $topicFile -PathType Leaf)) {
Write-Host "Document $topicFile in Topics does not exist" -ForegroundColor Red
Exit
}
# Load document to XML object
try {
[xml] $topic = Get-Content -Path $topicFile
} catch {
Write-Host "Document $topicFile parsing failed" -ForegroundColor Red
Exit
}
$path = Split-Path -Path $topicFile
$depth += 1
$topic.SelectNodes("//snippet") | ForEach-Object {
$snippetFile = $path
$snippetFile += "\"
$snippetFile += $_.src
$snippetFile += ".xml"
for ($i = 1; $i -lt $depth; $i++) {
Write-Host " " -NoNewline
}
Write-Host $_.src -NoNewline
Write-Host ".xml"
Snippets -topicFile $snippetFile -depth $depth
}
}
$topic = Split-Path -Path $topicFile -Leaf
Echo "Snippets in $topic"
Snippets -topicFile $topicFile -depth 0
Code: Select all
C:\scripts\>powershell.exe -File snippets_in_topic.ps1 -topicFile C:\HMproject\Topics\business_unmanaged_windows8_cantupgrade.xml
Snippets in business_unmanaged_windows8_cantupgrade.xml
snippet_ifcantupgrade_w8.xml
snippet_do_order_normal.xml
snippet_upgrade_endpoint_group_olderos.xml
snippet_upgrade_endpoint_manually.xml
snippet_dwn_endpoint_olderos.xml
snippet_upgrade_endpoint_manually_formore.xml
snippet_upgrade_to_w10_normal_w8.xml
snippet_upgrade_to_w10_why.xml