Bonjour,

ma commande 'Compress-Archive' ne fonctionne pas sur mon serveur 2008

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Compress-Archive : The term 'Compress-Archive' is not recognized as the name of a cmdlet, function, script file, 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 D:\test.ps1:35 char:5
+     Compress-Archive -Path ($Path + "index.txt") -CompressionLevel Optimal -Dest ...
+     ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Compress-Archive:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Terminé

PS C:\> $PsVersionTable

Name                           Value                                                                                                                              
----                           -----                                                                                                                              
PSVersion                      4.0                                                                                                                                
WSManStackVersion              3.0                                                                                                                                
SerializationVersion           1.1.0.1                                                                                                                            
CLRVersion                     4.0.30319.36470                                                                                                                    
BuildVersion                   6.3.9600.19170                                                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}                                                                                                               
PSRemotingProtocolVersion      2.2
Mais avec la version 5.1.1, pas de problème mon script fonctionne

Name                           Value
----                           -----
PSVersion                      5.1.17763.771
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.771
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1     
Mon script :
Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
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
# Parameter
Param(
    [Parameter()]
    [string]$Path = "C:\source\"
)
 
#Récupération des fichier txt commencant par 1988_test
$list_fictxt = Get-ChildItem -Path $Path | Where-Object {$_.Name -match "^1988_test_[0-9]{9}_[0-9]{14}.txt"}
 
#Parcours des fichiers précedemment récupéré
foreach ($fictxt in $list_fictxt) {
    #Récupère le nom du txt
    $ficName = $fictxt.BaseName
 
    #Renomme ne txt en index.txt
    Rename-Item -Path ($Path + $fictxt.Name) -NewName ($Path + "index.txt")
 
    #Zip du txt avec son ancien nom
    Compress-Archive -Path ($Path + "index.txt") -CompressionLevel Optimal -DestinationPath ($Path + $ficName + ".zip")
 
    #Supprime le index.txt
    Remove-Item -Path ($Path + "index.txt")
}
 
Write-Host "Terminé"
exit 0

Merci de votre aide d'avance
Birel