Prima di importare il mio modulo PowerShell (MyModule.psm1)
, ho scritto una funzione in esso:PowerShell: Modifica di un modulo già importato
Function T1()
{
Write-Host "T1 is just called" -ForegroundColor red
}
Nel mio MyModule.psd1
:
@{
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '2.0'
# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = '2.0'
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module
ScriptsToProcess = @()
# Modules to import as nested modules of the module specified in ModuleToProcess
NestedModules = @()
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# List of all modules packaged with this module
ModuleList = @()
# List of all files packaged with this module
FileList = @()
}
Questo è importata bene, quando ho copiato entrambi i file in:
C:\Users\fwaheed\Documents\WindowsPowerShell\Modules\MyModule
e sono in grado di eseguire T1
nella mia sessione PowerShell.
Ma ora ho voluto aggiungere una nuova funzione nella stesso modulo vale a dire .:
Function T2()
{
Write-Host "Its now T2.." -ForegroundColor red
}
Anche dopo aver riavviato la mia sessione di PowerShell, non è mai riconoscono T2
, tuttavia T1
funziona ancora.
Come posso modificare il mio modulo già importato in modo tale che le modifiche sono immediatamente disponibili ...
Grazie mille ...
'import-module mymodule -force' non è sufficiente? –
Provato anche quello, ma invano ... :( –
Grazie amico ... Appena rimosso il modulo, importato di nuovo e provato con "import-module MyModule -force" E ha funzionato aggiungendo altre 4 funzioni .. –