Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Last active December 31, 2021 19:54
Show Gist options
  • Save wsmelton/5f1216307efdaf40fbc5ebe49d5f65c4 to your computer and use it in GitHub Desktop.
Save wsmelton/5f1216307efdaf40fbc5ebe49d5f65c4 to your computer and use it in GitHub Desktop.
Commands index page comparison to Commands in dbatools module (cmdlet and function)
function Find-MissingCommands {
<#
.SYNOPSIS
Find missing commands between the dbatools.io/commands and dbatools Module public functions
.PARAMETER ModulePath
Path to dbatools local repository
.PARAMETER CommandPagePath
Full path to the index.html commands page (e.g. c:\git\web\commands\index.html)
.PARAMETER Reverse
Compare commands found in the CommandPagePath to those in the module
.EXAMPLE
Find-MissingCommands
Returns string list of the commands not found in the Commands page.
#>
[cmdletbinding()]
param(
[string]
$ModulePath = 'C:\git\dbatools',
[string]
$CommandPagePath = 'C:\git\web\commands\index.html',
[switch]
$Reverse
)
$commandPage = Get-Content $CommandPagePath
if (-not (Get-Module dbatools)) {
Import-Module $ModulePath
}
$commands = Get-Command -Module dbatools -CommandType Cmdlet, Function | Where-Object Name -NotIn 'Where-DbaObject','New-DbaTeppCompletionResult' | Select-Object -Expand Name
if ($Reverse) {
$commandRefs = $commandPage | Select-String '<a href="http://docs.dbatools.io/' | ForEach-Object { $_.ToString().Trim() }
$commandRefList = foreach ($ref in $commandRefs) {
$ref.ToString().SubString(0,$ref.ToString().IndexOf('">')).TrimStart('<a href="http://docs.dbatools.io/')
}
$commandRefList | Where-Object { $_ -notin $commands }
} else {
#find missing
$notFound = $commands | ForEach-Object -ThrottleLimit 10 -Parallel { $foundIt = $using:commandPage | Select-String -Pattern $_; if (-not $foundIt) { $_ } }
# found
$found = $commands | ForEach-Object -ThrottleLimit 10 -Parallel { $foundIt = $using:commandPage | Select-String -Pattern $_; if ($foundIt) { $_ } }
Write-Host "Tally: Total Commands ($($commands.Count)) | Found ($($found.Count)) | Missing ($($notFound.Count))"
$notFound
}
}
@wsmelton
Copy link
Author

That change truncates the command names found in the index:

image

I've updated Gist with the current version that returns the expected content:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment