Import-Module pscx Error

Topics: User Forum
Jun 7, 2010 at 6:24 PM

Here's the error I'm getting when running Import-Module pscx

I am running on a Windows 7 Enterprise x64 box and am a domain admin.

Import-Module : Could not load file or assembly 'Pscx, Version=2.0.3782.38615, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)
At line:1 char:14
+ Import-Module <<<<  pscx
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Jun 29, 2010 at 3:46 PM
Edited Jun 29, 2010 at 3:46 PM
Have you typed "Get-ExecutionPolicy" to see what's its setting is? I think you need "unrestricted". Try this: Set-ExecutionPolicy unrestricted
Jul 2, 2010 at 10:22 PM
Edited Jul 2, 2010 at 10:48 PM

I have this exact same error too, Win7 Ultimate x64. I tried changing my execution policy to unrestricted, but that doesn't do anything.

EDIT: Actually it turned out I was having this problem because I was using the Modules folder in my user directory. In my environment, the My Docs folder is redirected to a file server and shared by UNC path (the path is "\\FILE01\<some stuff>\<my user>\My Documents\" ), I think this is why it broke. Moving the Pscx folder to %windir%\System32\WindowsPowerShell\v1.0\Modules let me import it. I changed my execution policy back to Remotesigned as well and it was fine.

Coordinator
Jul 3, 2010 at 2:04 AM

Importing modules from a network share has come up before as a problem.  I don't *think* this is specific to PSCX.

Developer
Jul 3, 2010 at 7:08 AM

It's a .Net trust issue -- until .Net 4 they don't trust network paths.  You have to modify the trust of your share (or assembly) using Caspol:

Set-Alias CasPol "$([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())CasPol.exe"
CasPol -polchgprompt off -machine -addgroup 1.2 -url file://\\YourServer\Modules\* FullTrust

Have a look at the wiki page about importing binary modules from network shares if you want more information.

 

 

Coordinator
Jul 4, 2010 at 1:18 AM
Edited Jul 4, 2010 at 1:19 AM

Hmm, according to this Brad Abrams post, the issue was fixed with .NET 3.5 SP1.  And this Vance Morrison blog post goes into the details.

Developer
Jul 4, 2010 at 3:01 AM

No, it doesn't.  What Brad and Vance Morrison wrote in their blog posts is correct, as far as it goes. Managed executables will run from network locations in .Net 3.5 SP1, but that's all they changed.

 That's basically what I wrote on the wiki: you can't load assemblies from a network location into an app that's running from a local "My Computer" location, and you can't load them into a hosted framework either (I think that means PowerShell.exe, since PowerShell is a native app that hosts the framework, right?) In any case, as far as I know, the fix in 3.5 SP1 is irrelevant for PowerShell.

 

Coordinator
Jul 4, 2010 at 4:13 AM

Ah, yeah that would make sense.  I knew I had heard about something (EXEs) loaded from network locations given full trust in .NET 3.5 SP1.  But I guess they took that a step further in .NET 4.0.  Well, given the deprecation of the CAS security model, I guess they took things a good deal further.  :-)

Developer
Jul 4, 2010 at 7:18 PM
Edited Jul 4, 2010 at 7:19 PM
Not quite true - UNC paths have had full trust since 3.5 SP1.
  
Never mind, didn't read the full thread. :)
-Oisin
On Sat, Jul 3, 2010 at 2:08 AM, Jaykul <notifications@codeplex.com> wrote:

From: Jaykul

It's a .Net trust issue -- until .Net 4 they don't trust network paths.  You have to modify the trust of your share (or assembly) using Caspol:

Set-Alias CasPol "$([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())CasPol.exe"
CasPol -polchgprompt off -machine -addgroup 1.2 -url file://\\YourServer\Modules\* FullTrust

Have a look at the wiki page about importing binary modules from network shares if you want more information.

 

 

Read the full discussion online.

To add a post to this discussion, reply to this email (Pscx@discussions.codeplex.com)

To start a new discussion for this project, email Pscx@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--

---
404 signature missing

Sep 15, 2010 at 9:17 PM
Edited Sep 15, 2010 at 9:41 PM

Nevermind, figured it out. Had to copy pscx to "%windir%\System32\WindowsPowerShell\v1.0\Modules" directory in addition to having it available in my network modules directory.

Tried your suggestion @Jaykul, but I'm still getting the error referenced @ the beginning of this thread.

Set-Alias CasPol "$([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())CasPol.exe"
CasPol -polchgprompt off -machine -addgroup 1.2 -url file://\\YourServer\Modules\* FullTrust

I've tried referencing the UNC path and the related mapped drive.  Any ideas?

 

Sep 29, 2010 at 2:00 AM

Alright, I ran into this same problem, and being really green to modules at all, I'm surprised I figured this out.  

If I COPY the Pscx folder from inside the archive folder to the $Home\windowspowershell\Modules folder it fails.  If you EXTRACT the folder to the proper location, it loads.  

Could it be something to do with the way zip folders have to be unblocked?

Coordinator
Sep 29, 2010 at 3:44 PM

The best approach is to unblock the PSCX zip file first, then open it and extract the contents to the Modules dir.

Jan 5, 2011 at 2:02 AM

I have the same problem.

However I can import other modules from a network location but not some others including the PSCX.

Developer
Jan 5, 2011 at 5:15 AM

Well, PSCX is a binary module: it has a DLL component. If your other modules are pure script modules, then only your ExecutionPolicy matters for them, but for the binary module you need to see the wiki page about importing binary modules from network shares...

Jan 10, 2011 at 4:32 AM

Thank you Jaykul.  I will check that out.

Jan 10, 2011 at 4:43 AM

Again thanks to Jaykul.

I copy the Pscx to my local drive and specify it to load from there.  That works fine.

Jan 11, 2011 at 7:57 PM

I found what worked was to launch powershell as the admin. Then my imports worked fine.

Jan 12, 2011 at 1:22 PM
fildaben wrote:

I found what worked was to launch powershell as the admin. Then my imports worked fine.

It's good to know.  Thanks.

Jul 5, 2011 at 10:51 PM

Is there anyway to launch a PS script as admin from a batch file?  I have a batch file that does a check to make sure Powershell 2.0 is loaded.  If it is then it fires up my script using "powershell -ExecutionPolicy Bypass -file OS_Hotfixes.ps1".  As others if I copy it to a local drive it works w/o issue, if not I get the same error as above.