@@ -88,5 +88,28 @@ $shortModuleInfos = Get-ChildItem -Path $builtinModulePath `
8888 Add-Member - InputObject $shortModuleInfo - NotePropertyName ' ExportedAliases' - NotePropertyValue $module.ExportedAliases.Keys - PassThru
8989 }
9090}
91- $jsonData [' Modules' ] = $shortModuleInfos
92- $jsonData | ConvertTo-Json - Depth 4 | Out-File ((Get-CmdletDataFileName )) - Encoding utf8
91+
92+ # Microsoft.PowerShell.Core is a PSSnapin, hence not handled by the previous code snippet
93+ # get-module -name 'Microsoft.PowerShell.Core' returns null
94+ # whereas get-PSSnapin is not available on PowerShell Core, so we resort to the following
95+ $psCoreSnapinName = ' Microsoft.PowerShell.Core'
96+ Write-Progress $psCoreSnapinName
97+ $commands = Get-Command - Module $psCoreSnapinName
98+ $shortCommands = $commands | select - Property Name, @ {Label = ' CommandType' ;Expression = {$_.CommandType.ToString ()}}, ParameterSets
99+ $shortModuleInfo = New-Object - TypeName PSObject - Property @ {Name = $psCoreSnapinName ; Version = $commands [0 ].PSSnapin.PSVersion.ToString()}
100+ Add-Member - InputObject $shortModuleInfo - NotePropertyName ' ExportedCommands' - NotePropertyValue $shortCommands
101+
102+ # Find the exported aliases for the commands in Microsoft.PowerShell.Core
103+ $aliases = Get-Alias * | where {($commands ).Name -contains $_.ResolvedCommandName }
104+ if ($null -eq $aliases ) {
105+ $aliases = @ ()
106+ }
107+ else {
108+ $aliases = $aliases.Name
109+ }
110+
111+ Add-Member - InputObject $shortModuleInfo - NotePropertyName ' ExportedAliases' - NotePropertyValue $aliases
112+
113+ $allShortModuleInfos = $shortModuleInfos + $shortModuleInfo
114+ $jsonData [' Modules' ] = $allShortModuleInfos
115+ $jsonData | ConvertTo-Json - Depth 4 | Out-File ((Get-CmdletDataFileName )) - Encoding ASCII
0 commit comments