这是一个奇怪的例子,但它解决了我的问题:
文件:Foo.psm1
class Foo
{
[OBJECT] GetSite ()
{
return Get-SPWeb -Identity 'http://mysharepointsite.com';
}
}
文件: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 ......
当这些类在同一个文件中时,它可以正常工作。
有什么建议吗?