No PowerShell in System.Management.Automation?
Asked Answered
O

1

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

Olnton answered 11/6, 2013 at 18:29 Comment(2)
What version of Windows are you on? I'm going to guess you're on Windows XP.Fecit
@Fecit Windows Server 2008 R2Olnton
P
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?

Prickly answered 12/6, 2013 at 0:38 Comment(5)
Thats what I initially thought which prompted my question here. I do have 2.0 installed thoughOlnton
Just to check, does this line run without error $ps = [powershell]::Create()?Prickly
It does. Also, just FYI I referenced this question to check my version. $psversiontable.psversion gives me Major: 2, Minor 0, Build -1, Revision -1 (Whats with the negative build and revision numbers?)Olnton
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).Prickly
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.Olnton

© 2022 - 2024 — McMap. All rights reserved.