Importing modules in paths with spaces

Topics: User Forum
Dec 11, 2012 at 6:51 AM

I'm attempting to use PS on my work machine (I've been playing with it at home up to now).

The network is set up so that my 'home' drive is on a network share and my 'documents' directory is in a path with a space in it... "\\Sharename\Users$\Me\My Documents".

I've installed PSCX in the correct place and with the correct name but when I try importing it I get this ...

Import-Module : Could not load file or assembly 'Pscx, Version=2.1.4676.34063, 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

Now, I've checked the permissions and I have full control on all of the files all of the way down this part of the tree.

I then tried proividing the path to the module, like this...

PS L:\> import-module "~\My Documents\WindowsPowershell\Modules\PSCX\PSCX"

But that just resulted in a slightly different error...

Import-Module : Could not load file or assembly 'Pscx, Version=2.1.4676.34063, 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 <<<<  "~\My Documents\WindowsPowershell\Modules\PSCX\PSCX"
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Clearly I'm doing something wrong, I'll be damned if I can figure out what though.

Sorry about this, but if anyone can offer any advice, I'd love to hear it.

 

--
Stuart

Dec 11, 2012 at 7:28 AM

OK I appear to have made it work, but I'd be grateful to know this is the way I would be expected to do this.

I've created a local folder \Powershell\Modules and installed PSCX under that.

I then imported the module using the full path to the file...

import-module c:\Powershell\Modules\PSCX\PSCX

This appeared to work, but a call to Get-Help pscx returned an error aout not being able to find 'HelpUri'...

Property 'HelpUri' cannot be found for type 'System.Management.Automation.CmdletBindingAttribute'.
At C:\PowerShell\Modules\PSCX\Modules\GetHelp\Pscx.GetHelp.psm1:407 char:19
+     [CmdletBinding <<<< (DefaultParameterSetName='AllUsersView', HelpUri='http://go.microsoft.com/fwlink/?LinkID=1133
16')]
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Playing a  hunch, I applied the fix to a help problem someone helped me out with over the weekend and, restarting the session I invoked the module like this ...

Import-Module -name c:\PowerShell\Modules\PSCX\PSCX -arg ~\Pscx.UserPreferences.ps1

Now, this returns an info message ...

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

'~\Pscx.UserPreferences.ps1' is not recognized as either a hashtable or a valid path

To load all PSCX modules using the default PSCX preferences execute:

    Import-Module Pscx

To load all PSCX modules except a few, pass in a hashtable containing
a nested hashtable called ModulesToImport.  In this nested hashtable
add the module name you want to suppress and set its value to false e.g.:

    Import-Module Pscx -args @{ModulesToImport = @{DirectoryServices = False}}

To have complete control over which PSCX modules load as well as the PSCX
options, copy the Pscx.UserPreferences.ps1 file to your home dir. Edit this
file and modify the settings as desired.  Then pass the path to this file as
an argument to Import-Module as shown below:

    Import-Module Pscx -arg ~\Pscx.UserPreferences.ps1

The nested module names are:

CD,DirectoryServices,FileSystem,GetChildItem,GetHelp,Net,Prompt,TabExpansion,TranscribeSession,Utility,Vhd,Wmi

But, other than that, it seems to work.

--
Stuart