1

I'm having trouble getting the PowerShell class to resolve. I'm following along with the example in this question.

I have a reference added to System.Management.Automation from C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll

I have using System.Management.Automation; included at the top of my class.

However, when I try to create an instance of powershell: PowerShell ps = PowerShell.Create(), PowerShell won't resolve.

Using ctrl+. to auto-add the fully-qualified namespace (or using statement) just suggests Microsoft.Powershell in place of PowerShell.

I'm very confused why this is happening as even the example included in the MSDN documentation on the PowerShell class has pretty much exactly what I have.

I am in .NET 3.5, Visual Studio 2010, and Windows Server 2008 R2

Community
  • 1
  • 1
tnw
  • 13,521
  • 15
  • 70
  • 111

1 Answers1

1

The PowerShell class is new to PowerShell 2.0. Make sure you're referencing the 2.0 version of SMA.dll. Do you have PowerShell 2.0 installed?

Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thats what I initially thought which prompted my question [here](http://stackoverflow.com/questions/17053786/2-0-version-of-system-management-automation). I do have 2.0 installed though – tnw Jun 12 '13 at 12:25
  • Just to check, does this line run without error `$ps = [powershell]::Create()`? – Keith Hill Jun 12 '13 at 13:58
  • It does. Also, just FYI I referenced [this question](http://stackoverflow.com/questions/1825585/how-to-determine-what-version-of-powershell-is-installed) to check my version. `$psversiontable.psversion` gives me Major: 2, Minor 0, Build -1, Revision -1 (Whats with the negative build and revision numbers?) – tnw Jun 12 '13 at 14:01
  • You must be adding a reference to the 1.0 version of SMA. I would look around on your system for other versions of the assembly. Try looking under Program Files (x86) (if you're on a 64-bit machine). – Keith Hill Jun 12 '13 at 14:04
  • Keith, I hate to conclude the question this way, but I opened up the project again this morning and `PowerShell` is now resolving. This is with the SMA assembly in the GAC, which I DID try yesterday. I really hate when the conclusion to a question is as inconclusive as this... maybe I just had too much coffee. Who knows. I appreciate your help though. – tnw Jun 12 '13 at 14:29