Conditions sous Powershell
Bonjour à tous,
J'ai un script powershell qui télécharge des fichiers d'installation de logiciels et qui les enregistre dans un dossier spécifique. (Invoke-WebRequest -Uri)
J'ai tenté de mettre en place une condition dans le script (if (!(Test-Path "$Dir\NotePad.exe")) qui fait que si le fichier d'installation n'est pas présent dans le dossier le fichier est bien téléchargé.
En revanche, si le fichier est bien présent, je souhaite que le script passe à l'étape suivante (lancement d'un .bat)
Je galère avec les conditions sous powershell.
Pourriez-vous éclairer ma lanterne ?
Ci dessous, le code Powershell :
Code:
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 69 70
| Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
# Download Soft
$Dir="C:\users\$env:username\Desktop\TEMP"
# Télécahrgement 7Zip
Clear-Host
if (!(Test-Path "$Dir\7Z.msi"))
{
Write-Output "###########################"
Write-Output "#~~ TELECHARGEMENT 7ZIP ~~#"
Write-Output "###########################"
Invoke-WebRequest -Uri "https://www.7-zip.org/a/7z1900-x64.msi" -OutFile "$Dir\7Z.msi"
}
# Téléchargement Ccleaner
Clear-Host
if (!(Test-Path "$Dir\Ccleaner.exe"))
{
Write-Output "###############################"
Write-Output "#~~ TELECHARGEMENT CCLEANER ~~#"
Write-Output "###############################"
Invoke-WebRequest -Uri "https://download.ccleaner.com/ccsetup566.exe" -OutFile "$Dir\Ccleaner.exe"
}
# Téléchargement EdgeChromium
Clear-Host
if (!(Test-Path "$Dir\EdgeChromium.msi"))
{
Write-Output "####################################"
Write-Output "#~~ TELECHARGEMENT EDGE CHROMIUM ~~#"
Write-Output "####################################"
Invoke-WebRequest -Uri "http://dl.delivery.mp.microsoft.com/filestreamingservice/files/0a781574-de1b-431e-87a3-ed7d0f66393b/MicrosoftEdgeEnterpriseX64.msi" -OutFile "$Dir\EdgeChromium.msi"
}
# Téléchargement Firefox
Clear-Host
if (!(Test-Path "$Dir\Firefox.exe"))
{
Write-Output "######################################"
Write-Output "#~~ TELECHARGEMENT MOZILLA FIREFOX ~~#"
Write-Output "######################################"
Invoke-WebRequest -Uri "https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=fr" -OutFile "$Dir\Firefox.exe"
}
# Téléchargement Java
Clear-Host
if (!(Test-Path "$Dir\Java.exe"))
{
Write-Output "###########################"
Write-Output "#~~ TELECHARGEMENT JAVA ~~#"
Write-Output "###########################"
Invoke-WebRequest -Uri "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=242060_3d5a2bb8f8d4428bbe94aed7ec7ae784" -OutFile "$Dir\Java.exe"
}
# Téléchargement NotePad++
Clear-Host
if (!(Test-Path "$Dir\NotePad.exe"))
{
Write-Output "################################"
Write-Output "#~~ TELECHARGEMENT NOTEPAD++ ~~#"
Write-Output "################################"
Invoke-WebRequest -Uri "https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v7.8.6/npp.7.8.6.Installer.x64.exe" -OutFile "$Dir\NotePad.exe"
}
# Téléchargement VLC
Clear-Host
if (!(Test-Path "$Dir\VLC.exe"))
{
Write-Output "##########################"
Write-Output "#~~ TELECHARGEMENT VLC ~~#"
Write-Output "##########################"
Invoke-WebRequest -Uri "https://mirror.cyberbits.eu/videolan/vlc/3.0.10/win64/vlc-3.0.10-win64.exe" -OutFile "$Dir\VLC.exe"
}
if (Test-Path "$Dir\7Z.msi")
{
Start-Process C:\Users\$env:username\Desktop\Test.bat
} |
Merci d'avance pour votre aide.