Visual Studio C# powershell

Discussion in 'Scripting' started by MrNico98, Mar 18, 2024.

  1. MrNico98

    MrNico98 MDL Junior Member

    May 9, 2023
    56
    7
    0
    Hi everyone, I wanted to start a string with powershell on C# in net8.0 but I can't find the compatible nuget
    upload_2024-3-18_14-52-4.png
    upload_2024-3-18_14-52-16.png

    Solution?
     

    Attached Files:

  2. stayboogy

    stayboogy MDL Addicted

    May 1, 2011
    855
    228
    30
    #2 stayboogy, Mar 23, 2024
    Last edited: Mar 23, 2024
    I am not sure but it should be "using PowerShell Shell = PowerShell.Create()" I think

    or no "using" necessary at all and done like

    PowerShell Shell = PowerShell.Create()


    see here: https://learn.microsoft.com/en-us/d...utomation.powershell?view=powershellsdk-7.4.0

    or if you are talking about adding a string of commands to the created powershell process, hard to know what you asking exactly from your post honestly and just looking at that snippet, but

    that would be handled as so:

    PowerShell shell = PowerShell.Create("get-process").
    AddCommand("foreach { $_.Name }", true);