@@ -192,6 +192,7 @@ function New-MarkdownHelp
192192 }
193193
194194 $commandName = $mamlObject.Name
195+
195196 # create markdown
196197 if ($NoMetadata )
197198 {
@@ -206,10 +207,20 @@ function New-MarkdownHelp
206207 }
207208 else
208209 {
209- $a = @ {
210- Name = $commandName
210+ # Get-Command requires that script input be a path
211+ if ($mamlObject.Name.EndsWith (" .ps1" ))
212+ {
213+ $getCommandName = Resolve-Path $Command
214+ }
215+ # For cmdlets, nothing needs to be done
216+ else
217+ {
218+ $getCommandName = $commandName
211219 }
212220
221+ $a = @ {
222+ Name = $getCommandName
223+ }
213224 if ($module ) {
214225 # for module case, scope it just to this module
215226 $a [' Module' ] = $module
@@ -1810,39 +1821,42 @@ function GetHelpFileName
18101821 return $CommandInfo.HelpFile
18111822 }
18121823 }
1813-
1814- # overwise, lets guess it
1815- $module = @ ($CommandInfo.Module ) + ($CommandInfo.Module.NestedModules ) |
1816- Where-Object {$_.ModuleType -ne ' Manifest' } |
1817- Where-Object {$_.ExportedCommands.Keys -contains $CommandInfo.Name }
1818-
1819- if (-not $module )
1824+ # only run module evaluations if the input command isn't a script
1825+ if ($CommandInfo.CommandType -ne " ExternalScript" )
18201826 {
1821- Write-Warning - Message ($LocalizedData.ModuleNotFoundFromCommand -f ' [GetHelpFileName]' , $CommandInfo.Name )
1822- return
1823- }
1827+ # overwise, lets guess it
1828+ $module = @ ($CommandInfo.Module ) + ($CommandInfo.Module.NestedModules ) |
1829+ Where-Object {$_.ModuleType -ne ' Manifest' } |
1830+ Where-Object {$_.ExportedCommands.Keys -contains $CommandInfo.Name }
18241831
1825- if ($module .Count -gt 1 )
1826- {
1827- Write-Warning - Message ($LocalizedData.MultipleModulesFoundFromCommand -f ' [GetHelpFileName]' , $CommandInfo.Name )
1828- $module = $module | Select-Object - First 1
1829- }
1832+ if (-not $module )
1833+ {
1834+ Write-Warning - Message ($LocalizedData.ModuleNotFoundFromCommand -f ' [GetHelpFileName]' , $CommandInfo.Name )
1835+ return
1836+ }
18301837
1831- if (Test-Path $module.Path - Type Leaf)
1832- {
1833- # for regular modules, we can deduct the filename from the module path file
1834- $moduleItem = Get-Item - Path $module.Path
1835- if ($moduleItem.Extension -eq ' .psm1' ) {
1836- $fileName = $moduleItem.BaseName
1837- } else {
1838- $fileName = $moduleItem.Name
1838+ if ($module.Count -gt 1 )
1839+ {
1840+ Write-Warning - Message ($LocalizedData.MultipleModulesFoundFromCommand -f ' [GetHelpFileName]' , $CommandInfo.Name )
1841+ $module = $module | Select-Object - First 1
1842+ }
1843+
1844+ if (Test-Path $module.Path - Type Leaf)
1845+ {
1846+ # for regular modules, we can deduct the filename from the module path file
1847+ $moduleItem = Get-Item - Path $module.Path
1848+ if ($moduleItem.Extension -eq ' .psm1' ) {
1849+ $fileName = $moduleItem.BaseName
1850+ } else {
1851+ $fileName = $moduleItem.Name
1852+ }
1853+ }
1854+ else
1855+ {
1856+ # if it's something like Dynamic module,
1857+ # we guess the desired help file name based on the module name
1858+ $fileName = $module.Name
18391859 }
1840- }
1841- else
1842- {
1843- # if it's something like Dynamic module,
1844- # we guess the desired help file name based on the module name
1845- $fileName = $module.Name
18461860 }
18471861
18481862 return " $fileName -help.xml"
0 commit comments