Skip to content

Commit ab58624

Browse files
author
Kapil Borle
committed
Add script to create command file
1 parent 6009a23 commit ab58624

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Utils/New-CmdletDataFile.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
$builtinModulePath = Join-Path $pshome 'Modules'
2+
if (-not (Test-Path $builtinModulePath))
3+
{
4+
throw new "$builtinModulePath does not exist! Cannot create command data file."
5+
}
6+
7+
Function IsPSEditionDesktop
8+
{
9+
$PSEdition -eq $null -or $PSEdition -eq 'Desktop'
10+
}
11+
12+
Function Get-CmdletDataFileName
13+
{
14+
$edition = 'core'
15+
$os = 'windows'
16+
if ((IsPSEditionDesktop))
17+
{
18+
$edition = 'desktop'
19+
}
20+
else
21+
{
22+
if ($IsLinux)
23+
{
24+
$os = 'linux'
25+
}
26+
elseif ($IsOSX)
27+
{
28+
$os = 'osx'
29+
}
30+
# else it is windows, which is already set
31+
}
32+
$sb = New-Object 'System.Text.StringBuilder'
33+
$sb.Append($edition) | Out-Null
34+
$sb.Append('-') | Out-Null
35+
$sb.Append($PSVersionTable.PSVersion.ToString()) | Out-Null
36+
$sb.Append('-') | Out-Null
37+
$sb.Append($os) | Out-Null
38+
$sb.Append('.json') | Out-Null
39+
$sb.ToString()
40+
}
41+
42+
# Cannot use the ExportedCommands property of moduleinfo object because the parametersets field in an ExportedCommands element is empty
43+
Get-ChildItem -Path $builtinModulePath `
44+
| Where-Object {$_ -is [System.IO.DirectoryInfo]} `
45+
| ForEach-Object {Write-Progress $_; Get-Module $_.Name -ListAvailable} `
46+
| select -Property Name,@{Label='Version';Expression={$_.Version.ToString()}},@{Label='ExportedCommands';Expression={Get-Command -Module $_ | select Name,@{Label='CommandType';Expression={$_.CommandType.ToString()}},ParameterSets}} `
47+
| ConvertTo-Json -Depth 4 `
48+
| Out-File ((Get-CmdletDataFileName))

0 commit comments

Comments
 (0)