Sorry, can't seem to find this anywhere else, I hope someone here can help me.
I really want to start using VScode, and I set everything up to start using it for everything PowerShell/PowerCLI. There is one issue that I can't seem to fix. I set my default terminal to PowerShell, and I can run commands whether they are PowerShell or PowerCLI. When I'm in the script window, if I want to run a command as simple as Get-Cluster, it gives me the message below:
"You are not currently connected to any servers. Please connect first using a Connect cmdlet."
I made sure that I connected to vCenter before, and as long as I run the command in the terminal only, it works, but if I go up to where I would write out a script, it's as if that pane is being treated like it's an entirely different session. I included a screenshot. Thanks for any help.
I understand your explanation, but that does not seem to work for me. By default in my settings, I have this line in my setttings: "files.defaultLanguage": "powershell", so every new item defaults to powershell and vscode even shows the correct icon for the file. I did save my "untitled" file to "untitled.ps1". The file name changed, but I still can't run PowerCLI commands from it. It still produces the same message that I'm not connected to any servers. I also made sure that I don't have multiple terminals open, and I can run Get-Cluster from the terminal.
I typed Get-Cluster out in the terminal and it shows my clusters, and I included a screenshot. I then went to my code window, and ran the code, but it's saying that I'm not connected. I tried it on the saved "Untitiled-3.ps1" and I created a new file with Get-Cluster as my line of code, and when I run either saved or unsaved file, I get the same results that I'm not connected. Everything works fine when typed directly from the terminal.
I do see the "OUTPUT" shows that there is some tempCodeRunnerFile.ps1 that executes, I'm going to search around and see if there is some edit/change that may help. I appreciate the help so far.
Did you check the content of the launch.json file?
You can open that one through the menu and Debug - Open Configurations
When you select the Debug in the left bar, and open the debug drop-down list, do you see all the options that you have in the launch.json file?
Did you actually save that file somewhere?
Perhaps with a different name than untitled?
The problems are just an alias and when I was changing the PowerCLI configuration. I've also attached two screenshots. I also see the dropdown menu to launch with the current file or host process, etc. I'll try and change those just to see if they make a difference. I also definitely saved the "Untitled" file, I see the path, and I included it in the screenshot. I appreciate the help, I was hoping it was just a quick and easy setting that I missed, but I'm going to look around some more.
Well, like most things, it's seems to be user error, and since I'm the user, it must be me. The cmdlets work from the debug area, whether the file is saved or not, but it does not work when I just run the code. I wonder if it's the extension. I'll remove it, play around with it and see if that helps. Just curious, what extensions do you use? I included a screenshot. Thanks again for your help, I doubt that I would have tried the debug bar.
Thanks for your help. I removed the "code runner" extension, and I'm only running either F5 or F8 for debugging and it's working fine. I started installing extensions and looking at videos on vscode before actually using it, and I thought the issue was within the app, and not an extension. I'll probably add the extension back and figure out the problem, but for now, it's working just fine. I appreciate your help this time, and all the times in the past.
Since I can't really help with you with PowerCLI issues, I'll at least plug your book. Go out and buy:
You're welcome, it's the least that I could do. I'm probably going to install vscode on another VM first, and see if that works with the extensions, and then uninstall/reinstall on my other VM. At least my settings and everything are easy to copy and paste over. Thanks again.