Powershell result to c [Answered]

EEliasGPS11/12/2022
is it possible get a result from a powershell file after execution and store the result in a variable in c sharp? i have a powershell script that gives me an array and i want that array in c#
BBuddy11/12/2022
Maybe that can be of help
EEliasGPS11/12/2022
yeah i found that website to
EEliasGPS11/12/2022
but the problem is
EEliasGPS11/12/2022
they say "Create a System.Management.Automation.Powershell object" how do i do that. I'm knew to this so i'm sorry
BBuddy11/12/2022
Read the examples given
BBuddy11/12/2022
PowerShell ps = PowerShell.Create();
ps.AddScript(File.ReadAllText(@"D:\PSScripts\MyScript.ps1")).Invoke();
EEliasGPS11/12/2022
yeah
EEliasGPS11/12/2022
but look
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
i can't use create
EEliasGPS11/12/2022
so there is somthing wrong
BBuddy11/12/2022
EEliasGPS11/12/2022
bruh my powehsell is glitching
EEliasGPS11/12/2022
i alraedey did that
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
sometimes its red and sometimes not
BBuddy11/12/2022
You have not imported the namespace
BBuddy11/12/2022
System.Management.Automation
EEliasGPS11/12/2022
like this?
EEliasGPS11/12/2022
Image
BBuddy11/12/2022
No
EEliasGPS11/12/2022
ow ok
EEliasGPS11/12/2022
using?
BBuddy11/12/2022
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
here you see red
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
and now good
EEliasGPS11/12/2022
how?
EEliasGPS11/12/2022
nothing changed
EEliasGPS11/12/2022
its changing every 2 sec
BBuddy11/12/2022
Probably because VSCode / Omnisharp
EEliasGPS11/12/2022
yeah vscode is glithcing as hell
BBuddy11/12/2022
If you're a beginner and you're on Windows, I highly recommend Visual Studio
BBuddy11/12/2022
which is different from Visual Studio Code
EEliasGPS11/12/2022
i'm not a real beginner, but i'm a beginner in c#
EEliasGPS11/12/2022
ohh serious?
BBuddy11/12/2022
Yes.
EEliasGPS11/12/2022
but i'm used to program in vscode
BBuddy11/12/2022
If you're used to VSCode and you know dotnet CLI.
You should be fine.
BBuddy11/12/2022
But yeah, VSCode can be a little glitchy. Just something you need to live with I guess :bing_shrug:
EEliasGPS11/12/2022
oh ok thx
EEliasGPS11/12/2022
visual studio is so weird to
EEliasGPS11/12/2022
i open a folder and i see nothing
EEliasGPS11/12/2022
Image
BBuddy11/12/2022
You should not open the folder
BBuddy11/12/2022
but the project itself
BBuddy11/12/2022
*.csproj
BBuddy11/12/2022
or if a *.sln file exists, then choose that over *.csproj
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
i need to click on this right?
BBuddy11/12/2022
Make sure you install the workloads
BBuddy11/12/2022
Image
EEliasGPS11/12/2022
yeah thats already done
BBuddy11/12/2022
Then press that
Image
EEliasGPS11/12/2022
ok
BBuddy11/12/2022
Image
BBuddy11/12/2022
Open that if no *.sln file exists
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
ok
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
bruh
BBuddy11/12/2022
press view
EEliasGPS11/12/2022
Image
EEliasGPS11/12/2022
i cliked solution explorer
BBuddy11/12/2022
Now you can navigate it
BBuddy11/12/2022
just click on a file and start going
EEliasGPS11/12/2022
oh thx
EEliasGPS11/12/2022
i'm so noob in visual studio and c#
EEliasGPS11/12/2022
unbelievable
EEliasGPS11/12/2022
hahah
BBuddy11/12/2022
I did not notice the class you made is called PowerShell, lol.

I recommend renaming it as it can conflict with other classes called 'PowerShell'
EEliasGPS11/12/2022
i did that
EEliasGPS11/12/2022
ahh
BBuddy11/12/2022
Sweet!
EEliasGPS11/12/2022
does not exists
Image
BBuddy11/12/2022
Right-click the project in solution explorer
BBuddy11/12/2022
press Manage Nuget packages
BBuddy11/12/2022
Image
BBuddy11/12/2022
Browse for that nuget package, click it, then press install
BBuddy11/12/2022
Image
EEliasGPS11/12/2022
good but he can't find Powerhsell
Image
BBuddy11/12/2022
Class scope versus method scope
BBuddy11/12/2022
it can only be inside a method
EEliasGPS11/12/2022
ahh
EEliasGPS11/12/2022
he still can't find Powerhsell
Image
BBuddy11/12/2022
hover over Powershell, click the lightbulb on the left.
BBuddy11/12/2022
What options do you have?
EEliasGPS11/12/2022
Image
BBuddy11/12/2022
Did you install the package successfully?
EEliasGPS11/12/2022
yes but i used another version
BBuddy11/12/2022
Ah, that's why.
BBuddy11/12/2022
It is only available in version 7.0.0 and above
EEliasGPS11/12/2022
because i use .net core 6
EEliasGPS11/12/2022
and i can't use the latest version
EEliasGPS11/12/2022
how do i fix that