How to link powershell script to xaml (Visual studio for Blend) - powershell

I am new to Powershell and Visual Studio Blend.
I have created a UI using Microsoft Blend for Visual Studio which has got text box,combobox,label.
I have a Powershell script that needs to be run according to the list items in combobox.
How do I link powershell with the XAML in VS (Blend)such that if i choose a combobox the output should be displayed in the below label I have created. Basically I need to insert Powershell inside the XAML.
I have pure powershell script that executes well , i need to execute this using a GUI.

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.

Saving Aliases for powershell in Visual Studio code

I'm pretty new to both visual studio code and PowerShell, mostly used gitBash before. I'm just wondering if there is a way to save aliases that I set in the powershell, so I don't have to redo them everytime I restart the application.
I tried a few google searches but could not find the answer to my question.
Thank you.
S
If you're using Visual Studio Code with the PowerShell extension, you're using the PIC (PowerShell-Integrated Console) in the Visual Studio Code's integrated terminal, which has its own $PROFILE file, separate from stand-alone PowerShell installations.
You can open this $PROFILE file from the PIC as follows:
psedit $PROFILE
Any alias definitions or functions you place in there will be available in future PIC sessions by default - but only there.
Alternatively, to share definitions with a stand-alone PowerShell installation, dot-source its $PROFILE file; e.g., to dot-source:
the current user's Windows PowerShell profile, use:
. ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
the current user's PowerShell (Core) 7+ profile, use:
. ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

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.

Why does Visual Studio Code open my PowerShell files in a separate shell using 5.1 instead of Core?

I have "terminal.integrated.shell.windows": "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe" set in my settings.json file, and when I open VS code without any files open the terminal is set to pwsh, but when I open a PowerShell script, there is suddenly a second terminal (PowerShell Integrated Console) and running the debugger results in PowerShell 5.1 being used instead of 6 (Core).
What do I need to do to get PowerShell version 6 used whenever I open a .ps1 document? Running it from the command line works, but is a pain.
The PowerShell Integrated Console is what the PowerShell extension uses to process .ps1 files and is controlled by a different setting (powershell.powerShellExePath).
You can change this setting easily by opening a .ps1 file, then clicking on the "5.1", "6.0", etc. icon in the bottom right of the status bar. This will open the PowerShell Session Menu where you can select which version of PowerShell you want the extension to use (out of the versions you have installed).
Your choice will then be persisted in your user settings under powershell.powerShellExePath.

Can I detect in Powershell that I am running in VS Code's integrated terminal?

I would like to modify the standard PowerShell profile in Windows if the Powershell opens inside VS Code integrated terminal (when you are editing e.g. python scripts in VS Code, rather than PS scripts, which opens the ISE profile in any case).
Is there some environmental variable that gets set by the integrated PowerShell? Or is there some way of opening Powershell with a particular profile, instead of the default?
Thanks
VS Code creates an environment variable named TERM_PROGRAM. You can check it for a value of vscode, something like this:
if($env:TERM_PROGRAM -eq 'vscode') {
# do some stuff...
}
If you want to check if you're running within PowerShell Integrated Console (ships with PowerShell extension) under vscode and not just any powershell console running under vscode, you can:
if ($Host.Name -eq 'Visual Studio Code Host') {
Write-Output 'PowerShell Integrated Console'
}
This is meaningful to detect because it is the only powershell console host that provided full debugger support (eg. break on exception experience) and debugger integration with vscode.
You said you're into modifying profile when running within vscode, then you should check (again with PowerShell integrated console which ships with PoweShell extension):
PS> $PROFILE.CurrentUserCurrentHost
C:\Users\username\Documents\PowerShell\Microsoft.VSCode_profile.ps1
PS> $PROFILE.AllUsersCurrentHost
C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
If people are working on PowerShell code within Visual Studio Code, then why they would NOT install PowerShell extension which ships with a specific console that fully integrates with Visual Studio code and on the top of that, provides you a profile file specifically geared towards Visual Studio code?