I am currently evaluating PowerShell Universal for our Org and was having issues connecting to the server with the VSCode Extension.
First the extension starts off:
PS C:\Users\[USER]> Import-Module (Join-Path 'c:\Users\[USER]\.vscode\extensions\ironmansoftware.powershell-universal-4.2.4\out' 'Universal.VSCode.psm1')
PS C:\Users\[USER]> Install-UniversalModule -Version 'failed'
Import-Module: Cannot bind parameter 'RequiredVersion'. Cannot convert value "failed" to type "System.Version". Error: "Version string portion was
too short or too long. (Parameter 'input')"
Import-Module: Cannot bind parameter 'RequiredVersion'. Cannot convert value "failed" to type "System.Version". Error: "Version string portion was
too short or too long. (Parameter 'input')"
I then run the Install-UniversalModule without the -Version ‘failed’ to get it to install. Then
PS C:\Users\[USER]> Connect-PSUServer -ComputerName 'http://[SERVER]:5000' -AppToken 'xxx'
Connect-PSUServer: Call failed with status code 401 (Unauthorized): GET http://[SERVER]:5000/api/v1/accessible
However, if I do an Invoke-WebRequest or Invoke-RestMethod, I can successfully connect to /api/v1/accessible with the app token.
Any idea on how I can get the extension to connect to PowerShell Universal 5?
The extension can be installed from the VSC extension database and its settings contain all of the configuration needed. Are you able to see the extension installed?
Name: PowerShell Universal
Id: ironmansoftware.powershell-universal
Description: Visual Studio Code tools for PowerShell Universal
Version: 4.2.4
Publisher: Ironman Software
VS Marketplace Link: PowerShell Universal - Visual Studio Marketplace
Both the http and https connection profiles display the same error when attempting to connect via the Connections pane; the previously posted error when running Connect-PSUServer. It also pops up a toast error with
Failed to query API endpoints. Request failed with status code 401 This is a connection error. Click Settings to adjust your connection settings or App Tokens to generate a new token.
Sorry for misunderstanding - I see now that is the expected/traditional output for the extension. Just needed to reprompt my own memory by testing.
The -Version 'failed' speaks volumes to me. Can you try uninstalling and reinstalling the extension? It looks like the PSM1 is missing from the expected location. You can export the settings.json elsewhere to make sure your settings save and import them after reinstalling. You can also check that location mentioned in the automatic Import-Module call and see if the PSM1 is present there?
I’ve removed and reinstalled it a few times, but no luck. I even manually removed the extension folder after removing in case something was getting stuck during uninstall. Additionally, I attempted to configure and run the extension while running in Administrator mode, but the same error persists.
Looks like the Universal.VSCode.psm1 is present and is getting loaded properly. I continue to have to manually run Install-UniversalModule to get it configured (currently doing Install-UniversalModule -Version '5.0.7', let me know if I should try a different version)
I’m going to attempt to get VSCode and the extension installed on the same system that has Universal install. Not the ideal config, as my development machine is different from the Universal machine, but figure it wouldn’t hurt to try. Although, I can’t imagine it being a connection issues, since Invoke-RestMethod works with the correct headers supplied.
Please let me know if I can provide any additional information or if you have any other steps to try.
Since you’re using the config file to connect to multiple PSU instances (even though they’re likely the same instance, just on different protocols/ports), and each of the respective connections has its own settings, I wonder if having the powerShellUniversal.url, powerShellUniversal.apptoken variables at the top are maybe conflicting with the other entries and it doesn’t know which to use. Maybe instead of leaving them blank, just try deleting those lines altogether to see if that helps.
During the reinstall of the extension, I removed any blank entries in my settings. Unfortunately, still getting 401 Unauthorized errors when using Connect-PSUServer or when trying to connect with the extension.
Additionally, I have installed VSCode (machine install, I have user install on my development system, so was hoping this change would fix it, unfortunately not ) on the same system as I have Powershell Universal (also just updated to 5.0.9 from 5.0.7). The extension also does not connect to the Universal instance when trying to connect via localhost.
I attempted to add the following to my appsettings.json, but still getting 401 Unauthorized:
I also attempted to add the flag-TrustCertificate to the Connect-PSUServer, but am getting “A parameter cannot be found that matches parameter name TrustedCertificate”
I suppose I should ask, does the VSCode extension/PSU Model support the latest PSU 5?
Tokens generated when unlicensed do not work. After I put in a trial license, I generated a new token, which looked significantly different from the token proved before licensing.
After putting in this new token into the extension, everything started to work.