1

It's a odd example but it gets my issue across:

FILE: Foo.psm1

class Foo
{
    [OBJECT] GetSite ()
    {
        return Get-SPWeb -Identity 'http://mysharepointsite.com';
    }
}

FILE: Bar.psm1

Using MODULE ".\Foo.psm1";

class Bar : Foo
{
    Bar ()
    {
        Add-PSSnapin 'Microsoft.SharePoint.PowerShell';
    }
}

CONSOLE:

PS C:\test> Using MODULE "C:\Test\Bar.psm1";

PS C:\test> $myBar = [Bar]::new();

PS C:\test> $myBar.GetSite();
Get-SPWeb : The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.
At C:\Test\Foo.psm1:5 char:16
+         return Get-SPWeb -Identity 'http://mysharepointsite.com ...
+                ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

HOWEVER ...

When the classes are in the same file, it works fine.

Any suggestions?

Vidarious
  • 746
  • 2
  • 10
  • 22
  • Snapins are weird.. they just don't it into the modern concepts of PS. There's similar behavior when loading the snapin inside a module that explicitly exports certain functions. I would just load it differently, like inside your `$Profile`. – Thomas Glaser Aug 28 '17 at 06:20

0 Answers0