Eu tenho um módulo personalizado no Powershell. Consiste em dois arquivos, o Copy-Move.psm1 e o Copy-Move.psd1.
No Copy-Move.psm1 eu tenho várias funções das quais apenas exporto a função "Copy-MoveFiles" usando o seguinte comando no final
function Copy-MoveFiles
{..}
Export-ModuleMember Copy-MoveFiles
Eu coloquei os arquivos no seguinte diretório:
> C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Copy-Move
Eu iniciei uma tela de comando do Powershell e executei o seguinte comando:
Import-Module Copy-Move
Não há erros e quando executo o seguinte comando:
Get-Module Copy-Move
Eu obtenho o seguinte resultado:
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0 Copy-Move
Como você pode ver, não tenho funções exportadas, embora tenha exportado explicitamente a função como um membro do módulo. O manifesto do módulo não filtra as funções a serem exportadas porque usei um curinga para exportar a função em:
FunctionsToExport = '*'
Eu devo ter esquecido alguma coisa. Eu fiz isso dezenas de vezes, mas não consigo fazer as coisas funcionarem dessa vez.
O código do módulo:
Copy-Move-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
Copy-Move.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 = ''
}
Alguém sabe o que eu fiz de errado?