debugging powershell script file (PS1) from C# - powershell

We have created PS1 files.We are able to call the function in PS1 file from C# using Runspace,Pipeline etc.I am able to debug only upto "pipeline.Invoke()".
But now my question is whether it is possible to debug the PS1 file from pipile.Invoke()?
I mean Pressing F11 on "pipeline.Invoke()" can take me into the PS1 files? I basically want to debug the powershell script files from C#.

It's possible, but not particularly feasible. You have to directly interact with the runspace's debugger events, and essentially build your own engine integrating that into Visual Studio. This would be quite a time consuming, which is why it hasn't been done.

Related

VSCode - Automatically pick debugger

I have an Ansible workspace where I'm writing YML, PowerShell, and Python. Because of how things are set up where I work, I can't directly debug the YML files, so I need a custom launch configuration to run the files the way they are needed.
I'd love to just assign this to only YML extensions and leave the default debugger for Python and PowerShell files, as I switch between them quite often.
My current setup has a debug.ps1 file that will automatically switch between what it should launch based on the file that was debugged, but the Python files launch without the help of the Python debugger. I'd love for some way to either make that script launch the Python debugger, or make some sort of pre-debug task that tells VSCode what debugger to use.
Is there any way to do this?
Thanks!

Launching Visual Code .net debugger from Powershell

I am looking for a way to launch the "Run and Debug" functionality of Visual Code from an externally running PowerShell (PS) script. My project has 19 separate APIs that sometimes all need to be started together. To facilitate local development I already have a PS script that updates all my local.settings.json files depending on which services are running locally and which database I am using. It would be nice and save time if I could somehow also "reach into" Visual Code and launch the services as well.
Searching the internal for solutions has been difficult because all queries having to do with "powershell" and "Visual Code" lead to discussion of writing PS in Visual Code.
Thanks for any suggestions / directions to look / notification that this is impossible.

Win'2019 is detecting my scripts with the Win32/Casur.A!cl trojan

I have a windows batch script that, depending on the user menu selection, opens a powershell.exe and passing a variable to run a .ps1 script. I then use Bat To Exe Converted (v3.0.10) to convert it to an exe. A few hours ago I made changes to the PS script and copied it to the Win'2019 server and it accepted it. Now, I just changed two letters in a write-host message command and it keeps quarantining the file. Since this will be passed to customers I can't be telling them to ignore it or white list it.
I'm guessing the .bat and .ps1 files are throwing Windows Defender off. Funny how it was fine just a few hrs ago. Even if I undo the 2 letters I added it still deleting the exe.
The .bat is quite big and it'd be very difficult for me to convert and add inside the .ps1 script in hope of not setting off the trojan. What other options do I have to fix this? Is there a process or url to notify MS about this to get them to fix this false positive?
NOTE: No other Windows version or 3rd party antivirus that I've tried is detecting the exe infected. Only Win'2019's Defender is.
It looks like MS has fixed the false-positive with my code. I came in to work this morning and tried to copy the exe again and this time it worked. I didn't even contact MS (we don't have a support contract anyway).
Btw the exe consisted of a bat and ps1 script that just downloads some public install files (such as 7zip) from an https address, saves them and when running the exe the user would just get a menu of which of the downloaded programs they want to install.
The issue can be reproduced creating a simple new console application (Language : C++) with Visual Studio 2019 (Community Edition) and then just run program: Ctrl + F5. The solution that worked for me, to run the program, was to add the folder as an exclusion in Windows Defender Antivirus. I couldn't find any solution on other threads

Executing powershell script from Onenote

I'm using onenote as a documentation tool for some trivial tests and I sometimes use scripts.
I was using aside multiple scripts for automating stuff.
I would like to include these scripts in Microsoft OneNote (it is possible to include file in Onenote pages).
Then the objective is to execute the script from there.
It is not working; after double-clicking, a powershell window appear and disappear instantly.
Any ideas?
Edit The error message was caught in a screenshot:

Is there a way to run a PowerShell script through a JetBrains IDE?

I am currently using RubyMine which is an IDE developed for the Ruby programming language. Although, strangely enough, I find myself executing a lot of PowerShell scripts - something that seems to fall outside the scope of this product.
With some tinkering, I managed to associate .ps1 files with PowerShell, as well as having the correct syntax highlighting, but I am short one piece of functionality. I would like to run my PowerShell scripts the same way I run my Ruby scripts; through the Run menu.
My question is essentially: Is there a way to have RubyMine run my PowerShell script in a new shell, without me having to manually copy/paste the code?