The type or namespace name 'PowerShell' could not be found (are you missing a using directive or an assembly reference?)

  • Thread starter Thread starter knightshadow72
  • Start date Start date
K

knightshadow72

Guest
Hi Guys,

I'm just starting to get my feet wet in #C#and powershell. As part of my learning, I'm trying to run a powershell .ps1 script from C#. The content of the powershell script is just Importing an ActiveDirectory module and create a new AD user (New-ADUser).

My machine is windows 2016 with Powershell version 4.0 installed.

Steps That I've Done:

1. Create a ConsoleApp project in visual studio 2019 with .net 4.5 as the target Run time.

2. Download powershell package from nuget (System.Management.Automation 6.2.3).

3. Reference the System.Management.Automation Assembly (from nuget) to my project.

4. use the " using System.Management.Automation" .

5. Testing to create a new Powershell instance using :

PowerShell ps = PowerShell.Create()

But I got an error saying :

(1,1): error CS0246: The type or namespace name 'PowerShell' could not be found (are you missing a using directive or an assembly reference?)

(1,17): error CS0103: The name 'PowerShell' does not exist in the current context

>


I guess I won't be able to continue further until I resolve this issue.

Did I miss anything here ? I've searched the internet and I could not find any answer to this.

Any help would be appreciated.

Thanks,

Continue reading...
 
Back
Top