Пользовательский модуль Powershell CommandNotFoundException - PullRequest
0 голосов
/ 29 мая 2018

Когда я импортирую свой модуль, я не могу получить доступ к открытым членам.

Поместил мой модуль в C:\Program Files\WindowsPowerShell\Modules.

Когда я импортирую свой модуль в powershell с помощью: Import-Module StuiterModule -Verbose

, а затем введите Invoke-Reboot, выдается следующая ошибка:

Invoke-Reboot : The term 'Invoke-Reboot' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 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 line:1 char:1
+ Invoke-Reboot
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-Reboot:String [], CommandNotFoundExeption
    + FullyQualifiedErrorId : CommandNotFoundException

Кто-нибудь знает, что я делаю не так?


Обновление

Когда я помещаю -Force позади модуля импортавсе работает.Почему это так и как я могу это исправить?


Код:

StuiterModule.psm1

$Public = @( Get-ChildItem -Path "$PSScriptRoot\Public\*.ps1" )
$Private = @( Get-ChildItem -Path "$PSScriptRoot\Private\*.ps1" )

@($Public + $Private) | ForEach-Object {
    Try {
        . $_.FullName
    } Catch {
        Write-Error -Message "Failed to import function $($_.FullName): $_"
    }
}

Export-ModuleMember -Function $Public.BaseName

StuiterModule.psd1

#
# Module manifest for module 'StuiterModule'
#
# Generated by: StuiterSlurf
#
# Generated on: 29-5-2018
#

@{
# Script module or binary module file associated with this manifest.
RootModule = 'StuiterModule.psm1'

# Version number of this module.
ModuleVersion = '1.0.0'

# ID used to uniquely identify this module
GUID = '0254592e-b712-4d70-844c-6e38cec20ee5'

# Author of this module
Author = 'StuiterSlurf'

# Copyright statement for this module
Copyright = '(c) 2018 StuiterSlurf. All rights reserved.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Invoke-Reboot', 'Start-Program', 'Update-Program'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
    PSData = @{}
}
}

Public / Invoke-Reboot.ps1

# Reboot system

Function Invoke-Reboot {
[cmdletbinding()]
Param()

Write-Verbose "Starting reboot"
Restart-Computer
} 
...