1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Param(
[parameter(mandatory=$true)]
[string] $source,
[parameter(mandatory=$true)]
[string] $destination)
foreach($file in Get-ChildItem $source -Recurse)
{
$sub = $file.Directory
$sep = Split-Path ($sub) -NoQualifier
if($file.LastWriteTime -le $(Get-Date).AddMonths(-6) )
{
Write-host $file.LastWriteTime "-" $file.Name "-" $file.FullName
# Copy-Item $file.FullName -destination $dossier_de_recption
#New-Item $directory -ItemType directory -Path $destination
# New-Item -ItemType directory -Path "$destination\$directory" -Force | Out-null
#Move-Item $file.FullName -Destination $directory
$directory = "$destination\$sep"
if(!(Test-Path -Path "$directory" )){
Write-Verbose "Creating log location $directory."
#Write-Host -backgroundcolor green -ForegroundColor black "Creating log location $MonthPath."
Write-Verbose "MonthPat inside path test = $directory"
New-Item -ItemType directory -Path $directory | Out-null
}
move-item $file.FullName "$directory" -Force| Out-null
<#if (!(Test-Path $directory))
{
New-Item -ItemType directory -Path $directory -Force | Out-null
Move-Item $directory -Destination $destination -Force
}
Move-Item $file.FullName -Destination $directory -Force | Out-Null
#>
}
else {
echo "Le fichier ne correspond pas à la demande"
}
}
Split-Path : Impossible de lier l'argument au paramètre «Path», car il a la valeur Null.
Au caractère C:\Users\user1\Documents\WindowsPowershell\Copie_etic_6months.ps1:15 : 23
+ $sep = Split-Path ($sub) -NoQualifier
+ ~~~~~~
+ CategoryInfo : InvalidData : (:) [Split-Path], ParameterBindingValidation
Exception
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.P
owerShell.Commands.SplitPathCommand |
Partager