Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: Why do modules in the PSHome\Modules folder require the full p

Reply
 
Old 03-30-2009   #1 (permalink)
Bob Landau


 
 

Re: Why do modules in the PSHome\Modules folder require the full p

While it does turn out to be the way I've imported the library its not what
you thought.

In the case of the FileTransfer module; there really isn't one instead there
is a *.psd1 file which points to a .NET Interop library.

Turns out that if you import any library that via its manifest Powershell
will require you provide the complete path if you are to do this

Get-Command -Module <full path to module>


However if you import it via is module file *.psm1 then it only requires the
name of the module.

I will update the bug report to reflect reality rather than confusion.

thx
bob

"Kiron" wrote:
Quote:

> It has to do with the way you import the module, PS will assign that as the module's name while it's loaded.
> It's not recommended to use the Module's fullpath when importing it, the extension gets stripped, that's the problem you bumped into. To avoid this pass the name of the module's main file w/o extension, it'll work even with the fullpath up to the extension, but you'll have to retrieve it with the almost fullpath:
>
> $full = "$pshome\Modules\FileTransfer\FileTransfer.psd1"
> $fullNoExt = $full -replace '\.psd1$'
> $name = 'FileTransFER' # <- last three chars capitalized
> $full, $fullNoExt, $name | % {
> $x = @"
> write-host Starting... -f 14
> Import-Module $_
> gcm -Module $_
> (Get-Command Add-FileTransfer).ModuleName
> write-host Exiting... -f 14
> "@
> $cmd = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($x))
> powershell -nop -enc $cmd
> }
> # $full ...problem you described, $fullNoExt works, so does $name,
> # note the last three chars ...capitalized as it was imported
>
> --
> Kiron

My System SpecsSystem Spec
Old 03-30-2009   #2 (permalink)
Bob Landau


 
 

Re: Why do modules in the PSHome\Modules folder require the full p

I think I'm going to hide.

Kiron you are correct again. This had nothing to do with a manifest file.
The behavior I was complaining about is reproducible using a relative path
which resolves to the current directory.

import-module .\module.psm1 ## will require the module name to have the
complete path


import-module module.psm1 ## only requires the module name


"Bob Landau" wrote:
Quote:

> While it does turn out to be the way I've imported the library its not what
> you thought.
>
> In the case of the FileTransfer module; there really isn't one instead there
> is a *.psd1 file which points to a .NET Interop library.
>
> Turns out that if you import any library that via its manifest Powershell
> will require you provide the complete path if you are to do this
>
> Get-Command -Module <full path to module>
>
>
> However if you import it via is module file *.psm1 then it only requires the
> name of the module.
>
> I will update the bug report to reflect reality rather than confusion.
>
> thx
> bob
>
> "Kiron" wrote:
>
Quote:

> > It has to do with the way you import the module, PS will assign that as the module's name while it's loaded.
> > It's not recommended to use the Module's fullpath when importing it, the extension gets stripped, that's the problem you bumped into. To avoid this pass the name of the module's main file w/o extension, it'll work even with the fullpath up to the extension, but you'll have to retrieve it with the almost fullpath:
> >
> > $full = "$pshome\Modules\FileTransfer\FileTransfer.psd1"
> > $fullNoExt = $full -replace '\.psd1$'
> > $name = 'FileTransFER' # <- last three chars capitalized
> > $full, $fullNoExt, $name | % {
> > $x = @"
> > write-host Starting... -f 14
> > Import-Module $_
> > gcm -Module $_
> > (Get-Command Add-FileTransfer).ModuleName
> > write-host Exiting... -f 14
> > "@
> > $cmd = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($x))
> > powershell -nop -enc $cmd
> > }
> > # $full ...problem you described, $fullNoExt works, so does $name,
> > # note the last three chars ...capitalized as it was imported
> >
> > --
> > Kiron
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Modules days numbered? .NET General
CTP2: Modules using PSD1? PowerShell
RAM Memory Modules Incorrectly Detected ? Vista hardware & devices
Unable to see all modules PowerShell
Rebuild all modules under vista? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46