r/PowerShell • u/4r73m190r0s • 11d ago
Question PowerShell Editor Services on Linux, how to get completions that are Windows-specific?
For example, I'm not getting completions for Get-CimInstance and bunch of other Windows-specific modules.
4
u/purplemonkeymad 11d ago
Depends what you are completing, but most completers that are built-in don't use a precomputed list but actually resolve it from the system at complete time.
If you want you could export a list of what you want from a working command and then use that with a custom completer on linux. ie
Get-CimClass | % cimclassname | out-file "Get-CimInstance!ClassName.txt"Then add a completer that just reads those exports from the file.
Get-ChildItem ~/PSCompleters/*.txt | foreach-Object {
$command,$Parameter = $_.basename -split '!'
Register-ArgumentCompleter -CommandName $command -ParameterName $Parameter -ScriptBlock {
param ( $commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters )
$CompleterFile = "~/PSCompleters/${commandName}!${parameterName}.txt"
if (Test-Path $completerFile) {
return (Get-Content $completerFile | Where {$_ -like "$wordToComplete*"})
}
}
}This example uses a directory as the source of the completers and you can just add new files and re-run it to add new ones.
3
u/Thotaz 11d ago
That's a pretty good idea actually. On a Windows PC one could run a snippet to export all the Windows exclusive cmdlets as proxy commands into a dummy module that you simply import on a Linux machine. The basic concept is like this:
Get-Command -CommandType Cmdlet | ForEach-Object -Process { $MetaData = [System.Management.Automation.CommandMetadata]::new($_, $true) $Body = [System.Management.Automation.ProxyCommand]::Create($MetaData) @" function $($_.Name) { $Body } "@ } | Out-File -FilePath $HOME\DummyModule.psm1This would give you both command, and parameter completion (including parameterset logic), and you'd even get parameter value completions for enums/validateset. The only challenge here is that many of the commands will reference types that are unavailable without the module, so you'd have to find and replace those with
System.Object.
1
u/Vern_Anderson 11d ago
https://www.powershellgallery.com/packages/PSCompletions
PSCompletions runs on Windows and Linux and it's what I have used. However, I have noticed on some distros and PowerShell Core installs, that PSReadline module does not load automatically on startup and you have to fix that issue yourself.
1
2
u/y_Sensei 11d ago
You can't for cmdlets which are supported on the Windows platform only, and
Get-CimInstanceis one of them.