How do I connect VSCode to an IIS running PowerShell Universal?

Hi.

I have an IIS up and running with PowerShell Universal. I can browse the site and login.

How do I connect my VScode PU extension to this instance?
Its running on port 80
This is my settings.json:


{
    "security.workspace.trust.untrustedFiles": "open",
    "workbench.colorCustomizations" : {
        "terminal.foreground" : "#ffffff",
        "terminal.background" : "#012456"
    },
    "powershell.powerShellDefaultVersion": "Windows PowerShell (x64)",
    "powerShellUniversal.samplesDirectory": "C:\\Powershell Universal",
    "powerShellUniversal.connections": [
    
    ],
    "powerShellUniversal.url": "http://localhost",
    "powerShellUniversal.appToken": "SecretTOKEN"
}

I have downloaded the .zip file and extracted it to this path: C:\Powershell Universal

Hi Peter1,

I am assuming you have the PSU extension installed in your VS Code. From VS Code, you should be able to visit the extensions settings (Ctrl+Shift+X). Once you are in the extension settings for PSU, you will need to enter in the servername/hostname. It’s near the bottom of the settings (pictured).

Let us know if this helps.

Hi.

Mine looks like this:

I have tried with https://localhost:80 but that did not work

Edit:

When trying to connect with through a terminal in VScode I get this error:

Code:

Connect-psuserver -computername 'http://localhost' -AppToken 'SecretTOKEN'

What rights do the Token identity have?

My VSCode settings look like this, the Token identity has the Admin role.

{
    "powerShellUniversal.connections": [
        {
            "name": "Beta.MiddlewareDashboard",
            "samplesDirectory": "C:\\Users\\Someuser\\AppData\\Roaming\\Somepath",
            "url": "https://beta.middlewaredashboard.domain.org",
            "appToken": "TOKENHERE"
        },
        {
            "name": "Beta.SupportDashboard",
            "samplesDirectory": "C:\\Users\\Someuser\\AppData\\Roaming\\somepath",
            "url": "https://beta.supportdashboard.domain.org",
            "appToken": "TOKENHERE"
        }
    ],
    "powerShellUniversal.checkModules": false,

Hi.

The token identity is the build in Admin.
I have since made a new identity and made it Administrator and then made a token for this user and copied it in but its the same result:

WARNING: Failed to verify module and server version. Call failed with status code 404 (Not Found): GET http://iweb02/api/v1/version

Your code above is that from the settings.json? It just looks differend then mine.
Since im running on IIS and i am not using domain users or local users (only PowerShell Universal identities) could that cause issues? Do the have have correct permission to the folders on the webserver? The IIS application pool and site uses the local Administrator account so I would guess that there should be access to all folders

Edit:
Could it be my ‘appsettings.json’ that needs to be edited?

My PU installation is here on the webserver C:/PowerShell Universal. In here I have the ‘appsettings.json’ file.

I changed the url here to ‘http://iweb02’ as shown here:

image

But still I can’t get VScode to connect to my IIS running PU instance

I have IIS and PSU fresh installed, all what you need is to copy and paste apptoken in vscode powershell universal extension and the url should be like this with port number

http://iweb02:80

I have this in place. I must have messed something else up :frowning:

Since I am getting ‘Unauthorized’ error, could it be my Application pool in IIS that is wrongly configured?

I have chosen the webservers local admin user here. But this user is not in Powershell Universal.
Maybe I need to add something to the authentication.ps1? I think I have to add the local administrator account as a PU users so that these credentials are used to run dashboards and script, if that is possible?

What do you have configured in the authentication settings for IIS?

image

You dont need to mess with users and creds or anything else, as i mentioned earlier i did a fresh IIS PSU install and didnt need to do anything other than
1-login to psu
2-create an apptoken with role administrator
3-make sure you dont have any conflict modules in windows powershell or powershell 7 if you have it installed.
4-open vscode and install latest release of psu add-on
5-paste in your apptoken and the url in the settings of psu add-on.

thats it.

Hi Adam.

Actually my Anonymous Authentication was disabled. I have now enabled it and can run this command from VScode without errors:

Connect-psuserver -computername 'http://localhost' -AppToken 'InsertTokenHere'

This is progress! Thanks!

But for some reason vscode PU extension still can’t connect

This is my settings.json - I double checked the token is correct:

This is my appsettings.json:

Can you try this format?

"powerShellUniversal.connections" : [
      {
            "name": "Local",
            "url": "http://localhost:80",
            "appToken": "TOKENHERE"
        },
}

Did I insert it correct:

Probably not - Im getting this error in vscode:
AsPowerBar_Msgag968Kk

I’d remove the duplicates from line 9-13. You connection should show up in the PSU activity pane. There will be a connect button you can press to get it connected using the connection.

image

1 Like

That did the trick!

Thanks alot Adam and all who helped me!

1 Like