How to execute .PS1 file from Visual Studio 2017 project - powershell

I have a .PS1 file as part of Visual Studio 2017 project. Let me know, how to execute this script file in debug mode (VS debug mode)? also let me know, how to pass input variables to this script file?

Check out PowerShell Tools for Visual Studio and the PowerShell Class.

Related

powershell script to automate code coverage tests in visual studio?

Need to create a powershell script to automate code coverage tests in visual studio 2022.
Expected a properly formatted XML file to have been generated, which can then be imported into Excel for analysis.

Build installer projects from visual studio 2022 command line

Recently I upgraded a project to Visual Studio 2022. I am using command line to build the installer project (.vdproj) using the command something shown below
devenv.com <Solutionfile> /build <InstallerConfiguration>.
The command used to build file with VS 2019 but when trying to build the same with Visual Studio 2022 seems to be stuck. It seems that everything builds fine but the Visual Studio process does not exit after the project is built and causes the build pipeline to be stalled. I have disabled out of proc build to see if this was causing the issue but it does not help. Any one experience the same issue? I am using the most recent version of visual studio along with the Visual Studio installer project extension. Any other method of building the installer project? I have tried MSBuild command but it does not understand vdproj files.
This has been fixed with the latest release of VS 2022 17.3.6. Works fine for me now.

Did Windows 11 break Visual Studio Code

I 'upgraded' my Win10 system to Win11. Since then Visual Studio Code simply will not run my PowerShell scripts. What happens is the little 'Pause/Step-x/Restart/Stop' ribbon appears at the top. All I can do then is hit the Stop. I uninstalled & re-installed VS-Code to no avail. I deleted the .vscode folder in my user-profile, again to no avail.
I have both PowerShell 5.1.22000.65 Desktop and 7.1.3 Core installed on this system. VS Code is 1.58.2 (system setup). PowerShell extension is v2021.6.2.
The same scripts run happily in Windows Terminal, PowerShell command window and the ISE.
Any ideas please?
Thanks very much.
Update 13th August 2021: PowerShell scripts are now running as expected in Visual Studio Code.
VS Code is 1.59.0.
PowerShell Extension is 2021.8.0.
The most likely change to have enabled scripts to work again is the update to PowerShell 7.1.4 Core (was 7.1.3).

Start Developer PowerShell for VS 2019 from Azure DevOps pipeline

We have configured a windows virtual machine and deployed an agent there to build our code and run scripts.
In our VM we two different flavors of PowerShell command prompt:
Windows PowerShell
Developer PowerShell for VS 2019.
How can we start "Developer PowerShell for VS 2019" from our pipeline YAML script and execute our checked out .ps1 file there?
There are several flavors of PowerShell tasks that can be initiated from the pipeline though and not sure which one of them will serve the purpose. They are the following:
Azure PowerShell
PowerShell
PowerShell on Target Machine
Service Fabric PowerShell.
Which of the above represent "Developer PowerShell for VS 2019"?
The reason behind this specific flavor of PowerShell is:
Need to have some of the .NET Framework Tools (CorFlags.exe) which are only accessible in the "Developer PowerShell for VS 2019" and not in the other one.
The Developer PowerShell for VS 2019 is a regular PowerShell with a module imported, you can see exactly what in this way:
Go the Start menu and search for Developer PowerShell for VS 2019.
Right-click on it and Open file location - you will get this:
Now right-click again on the Developer PowerShell for VS 2019 shortcut and Properties.
You will see in the location that is run the regular PowerShell with some command:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell bc97b47b}"
Now, if you open a PowerShell and run the script there:
&{Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"; Enter-VsDevShell bc97b47b}
You will get the Developer PowerShell for VS 2019 and CoreFlags.exe will work:
So, you need to use the regular PowerShell task (your option 2) and run the above command at the begging of the script.
Note: you should copy exactly the command you see in the Properties, in each machine it could be different.

Can I debug ActiveDirectory with Visual Studio Code PowerShell extension?

It looks like the Visual Studio Code PowerShell extension is only able to debug scripts running on PowerShell Core.
Is it possible to debug PowerShell scripts when running PowerShell 5.1? I need to debug scripts accessing Active Directory.
On Windows, yes.
https://code.visualstudio.com/docs/languages/powershell#_multiversion-support
TL;DR: Just click the version number in the lower-right corner.