嵌套模块中无法识别模块助手功能

时间:2015-09-23 12:12:52

标签: powershell helper powershell-module

我有一个Powershell模块,包含4个.psm1文件:

  • DatabaseUserManagement.psm1 - 包含我的大多数公共cmdlet。
  • PermissionControl.psm1 - 包含最终的公共cmdlet。
  • ErrorHandling.psm1 - 包含私有错误处理函数。
  • 助手功能 - 包含大约10个小型私人助手功能。

无论出于何种原因,PermissionControl.psm1(Set-UserPermission)中的函数似乎无法看到任何辅助函数:

为了清晰起见添加了评论

PermissionControl.psm1

Function Set-UserPermission
{
    [CmdletBinding()]
    Param(
        # 3 parameters here. [string]$LogonName, [string]$Area and [string]$Permissions
    )

    $SamAccountName = (Get-SAMAccountName $LogonName) # Fails, can't find cmdlet.
    $Login = (Get-Login $SamAccountName) # Ditto
    $User = (Get-User $Login) # Ditto
    ...
)

DatabaseUserManagement.psm1

Function Add-DatabaseUser
{
    [CmdletBinding()]
    Param(
       # 3 parameters here. [string]$LogonName, [string]$UserName = '' and [switch]$FullAccess
    )

    $SAMAccountName = (Get-SAMAccountName $LogonName) # Works
    $Server = Get-Server # Ditto
    $Database = Get-Database # Ditto
    ...
)

HelperFunctions.psm1(仅限上一代码中提到的那些)

Function Get-SAMAccountName([string]$LogonName)
{
    Write-Output('{0}\{1}' -f (Get-DomainName), $LogonName)
}

Function Get-Login([string]$SAMAccountName)
{
    Write-Output((Get-Server).Logins[$SAMAccountName])
}

Function Get-User([Microsoft.SqlServer.Management.Smo.Login]$Login)
{
    Write-Output((Get-Database).Users[($Login.GetDatabaseUser((Get-Database).Name))])
}

Function Get-Server()
{
    Write-Output((New-Object Microsoft.SqlServer.Management.Smo.Server (Get-ServerInstanceName)))
}

Function Get-Database()
{
    Write-Output((Get-Server).Databases[(Get-DatabaseName)])
}

DatabaseUserManagement.psd1

@{
    ModuleToProcess = 'DatabaseUserManagement.psm1'
    ModuleVersion = '1.0.1'
    GUID = 'bd4390dc-a8ad-4bce-8d69-f53ccf8e4163'
    Author = 'removed'
    CompanyName = 'removed'
    Copyright = 'removed'
    Description = 'removed'
    PowerShellVersion = '2.0'
    DotNetFrameworkVersion = '4.0'
    ProcessorArchitecture = 'amd64'
    RequiredAssemblies = @(
        'Microsoft.SqlServer.Smo.dll'
    )
    NestedModules = @(
         'ErrorHandling.psm1'
        ,'PermissionControl.psm1'
        ,'HelperFunctions.psm1'

    )
    FunctionsToExport = @(
         'Add-DatabaseUser'
        ,'Get-DatabaseUser'
        ,'Get-DatabaseUserInformation'
        ,'Remove-DatabaseUser'
        ,'Set-UserPermission'
    )
    PrivateData = @{
         DatabaseName =       'removed'
        ;DomainName =         'removed'
        ;ServerInstancename = 'removed'
    }
}

我得到的错误如下:

Get-SAMAccountName : The term 'Get-SAMAccountName' 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 G:\My Documents\WindowsPowerShell\Modules\databaseusermanagement\PermissionControl.psm1:52 char:21
+     $SamAccountName = (Get-SAMAccountName $LogonName)
+                        ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-SAMAccountName:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

0 个答案:

没有答案