Created
December 30, 2021 17:28
-
-
Save KevinMarquette/aef8e6c819fcf4e9d71972c66dc8a70d to your computer and use it in GitHub Desktop.
A function that compares the commands listed in dbatools to the commands listed in the commands index page. No errorhandling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace System.Collections.Generic | |
function Find-CommandDelta { | |
param( | |
$ModulePath = 'C:\git\dbatools', | |
$Uri = 'C:\git\web\commands\index.html', | |
$Exclude = @('Where-DbaObject') | |
) | |
end { | |
if (-not (Get-Module dbatools)) { | |
Import-Module $ModulePath | |
} | |
[hashset[string]]$commands = Get-Command -Module dbatools -CommandType Cmdlet, Function | | |
Where-Object Name -notin $Exclude | | |
Select-Object -Expand Name | |
$CommandPage = 'C:\git\web\commands\index.html' | |
$commandPage = Get-Content $CommandPage | |
$pattern = '<a\ href="http://docs\.dbatools\.io/(?<command>.+)">(\k<command>)' | |
[hashset[string]]$uriCommand = foreach($line in $commandPage){ | |
if($line -match $pattern){ | |
$matches.command | |
} | |
} | |
# Clone hashset becuase ExceptWith modifies collection | |
[hashset[string]]$missing = $commands.clone() | |
$missing.ExceptWith($uriCommand) | |
# Clone hashset becuase ExceptWith modifies collection | |
[hashset[string]]$extra = $uriCommand.clone() | |
$extra.ExceptWith($commands) | |
return [PSCustomObject]@{ | |
Missing = $missing | |
Extra = $Extra | |
} | |
} | |
} | |
$delta = Find-CommandDelta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment