ExportedCommand leeres benutzerdefiniertes Modul PowerShell

ExportedCommand leeres benutzerdefiniertes Modul PowerShell

Ich habe ein benutzerdefiniertes Modul in Powershell. Es besteht aus zwei Dateien, Copy-Move.psm1 und Copy-Move.psd1.

In der Copy-Move.psm1 habe ich mehrere Funktionen, von denen ich nur die Funktion "Copy-MoveFiles" exportiere, indem ich am Ende den folgenden Befehl verwende

    function Copy-MoveFiles
    {..}

    Export-ModuleMember Copy-MoveFiles

Ich habe die Dateien in folgendem Verzeichnis abgelegt:

> C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Copy-Move

Ich habe eine Powershell-Eingabeaufforderung gestartet und den folgenden Befehl ausgeführt:

    Import-Module Copy-Move

Dort treten keine Fehler auf, auch wenn ich den folgenden Befehl ausführe:

    Get-Module Copy-Move

Ich erhalte folgendes Ergebnis:

    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   1.0        Copy-Move

Wie Sie sehen, habe ich keine Funktionen exportiert, obwohl ich die Funktion explizit als Modulmitglied exportiert habe. Das Modulmanifest filtert die zu exportierenden Funktionen nicht heraus, da ich zum Exportieren der Funktion ein Platzhalterzeichen verwendet habe:

    FunctionsToExport = '*' 

Ich muss etwas vergessen haben. Ich habe das schon Dutzende Male gemacht, aber dieses Mal kriege ich es einfach nicht hin.

Der Code des Moduls:

Kopieren-Verschieben-psm1

function Copy-MoveFiles
{
    <#
    .SYNOPSIS
    Deze functie maakt het mogelijk bestanden te kopieren of te verplaatsen
    door middel van een configuratiebestand.

    .DESCRIPTION
    Deze functie maakt het mogelijk om meerdere kopieer- of verplaatstaken uit 
    te voeren d.m.v. een enkel configuratiebestand. 

    .PARAMETER config
    Pad naar het configuratiebestand

    .PARAMETER logdir
    Pad waar het logbestand gemaakt moet worden.

    .EXAMPLE
    Copy-MoveFiles -config "C:\config.csv" -logdir "C:\log"
    #>

    param
    (
        [Parameter(Mandatory=$true,Position=1)][string] $config = ""
        , [Parameter(Mandatory=$false,Position=2)][string] $logdir = $PSScriptRoot + "\Log"
    )

    # Controleren of het pad naar het configuratiebestand klopt
    if(Test-Path $config)
    {
        # Aanmaken van de timestamp
        $timestamp = Get-Date -format yyyyMMdd

        # Opzetten van het logfile
        $logfile = $logdir + "\logfile_$timestamp.log"

        # Laden van de verschillende acties
        $actions = Import-Csv $config -Delimiter ';'

        # Controleer of er acties aanwezig zijn
        if($actions.count -ge 1)
        {
            Write-Logfile -logfile $logfile -level 3 -text "Actions found. Starting up..."

            # Loop door alle acties heen
            foreach($a in $actions)
            {
                # Ophalen van de 
                $source = $a.source
                $destination = $a.destination
                $createsubfolder = $a.createsubfolder
                $action = $a.action
                $filter = $a.filter

                # Controleer of er een speciale subfolder aangemaakt moet worden
                if($createsubfolder -ne ''){
                    switch($createsubfolder)
                    {
                        "[date]"{$destination = $destination + "\$timestamp"}
                    }
                }

                # Kijken of de doeldirectory bestaat
                if(!(Test-Path($destination)))
                {
                    # Maak de doeldirectory aan als deze niet bestaat
                    Write-Logfile -logfile $logfile -level 1 -text "Destination $destination doesn't exist. Creating.."
                    Show-Message -level 1 -text "Destination $destination doesn't exist. Creating.."
                    New-Item -ItemType directory -Path $destination | Out-Null
                }

                # Check to see if the source folder exists
                if(Test-Path($source))
                {
                    # Get the files from the source folder
                    $files = Get-ChildItem -Path $source | where { ! $_.PSIsContainer }

                    # Check if the source folder contains files
                    if($files.count -ge 1)
                    {
                        # Bekijk welke actie uitgevoerd moet worden
                        switch($action.ToUpper())
                        {
                            "COPY" 
                            {
                                Write-Logfile -logfile $logfile -level 1 -text "Copying from $source to $destination."
                                Show-Message -level 1 -text "Copying from $source to $destination."

                                # Probeer het commando uit te voeren
                                try
                                {
                                    # Bekijk of een filter benodigd is
                                    if($filter -ne '')
                                    {
                                        ROBOCOPY $source $destination $filter | Out-Null
                                    }
                                    else
                                    {
                                        ROBOCOPY $source $destination | Out-Null
                                    }
                                } catch
                                {
                                    Write-Logfile -logfile $logfile -level 3 -text "Error executing ROBOCOPY command: $_"
                                    Show-Message -level 3 -text "Error executing ROBOCOPY command: $_"
                                }
                            }

                            "MOVE" 
                            {
                                Write-Logfile -logfile $logfile -level 1 -text "Moving from $source to $destination."
                                Show-Message -level 1 -text "Moving from $source to $destination."

                                # Probeer het commando uit te voeren
                                try
                                {
                                    # Bekijk of een filter benodigd is
                                    if($filter -ne ''){
                                        ROBOCOPY $source $destination $filter /MOV | Out-Null
                                    }
                                    else
                                    {
                                        ROBOCOPY $source $destination /MOV | Out-Null
                                    }
                                } catch
                                {
                                    Write-Logfile -logfile $logfile -level 3 -text "Error executing ROBOCOPY command: $_"
                                    Show-Message -level 3 -text "Error executing ROBOCOPY command: $_"
                                }

                            }

                        }

                    }
                    else
                    {
                        Write-Logfile -logfile $logfile -level 2 -text "No files found in $source for action $action from $source. Continuing..."
                        Show-Message -level 2 "No files found in $source for action $action from $source. Continuing..."
                    }
                }
                else
                {
                    Write-Logfile -logfile $logfile -level 2 -text "Source folder $source doesn't exist. Continuing..."
                    Show-Message -level 2 "Source folder $source doesn't exist. Continuing..."
                }
            }
        }
        else
        {
            Write-Logfile -logfile $logfile -level 3 -text "No actions defined! Exiting..."
            Show-Message -level 3 "No actions defined! Exiting..."
            Exit(0)
        }
    }
    else
    {
        Write-Logfile -logfile $logfile -level 3 -text "Couldn't find config file! Exiting ..."
        Show-Message 3 "Couldn't find config file! Exiting ..."
        Exit(0)
    }
}

Export-ModuleMember Copy-MoveFiles

Kopieren-Verschieben.psd1

    @{

# Script module or binary module file associated with this manifest.
# RootModule = ''

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

# ID used to uniquely identify this module
GUID = 'a3af3a5b-d140-4450-98a1-4602a420e1bb'

# Author of this module
Author = 'Sander Stad'

# Company or vendor of this module
CompanyName = ''

# Copyright statement for this module
Copyright = ''

# Description of the functionality provided by this module
Description = 'Script voor het kopieren en verplaatsen van bestanden'

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

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
FunctionsToExport = '*'

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
AliasesToExport = '*'

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Weiß jemand, was ich falsch gemacht habe?

verwandte Informationen