You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.7 KiB

  1. $gitLabRepoUrl = "https://gitlab.altinea.fr/cyril.gorse/EDR"
  2. $filePath = "edrV2.ps1"
  3. $downloadUrl = "$gitLabRepoUrl/raw/master/$filePath"
  4. $downloadFolder = "$altineaFolderPath\install"
  5. $savePath = Join-Path $downloadFolder $filePath
  6. $altineaFolderPath = "C:\altinea"
  7. # Vérifier si le dossier Altinea existe, sinon le créer
  8. if (!(Test-Path $altineaFolderPath)) {
  9. New-Item -ItemType Directory -Path $altineaFolderPath | Out-Null
  10. # Définir le dossier Altinea comme un dossier caché
  11. (Get-Item $altineaFolderPath).Attributes = 'Hidden'
  12. }
  13. if (!(Test-Path $downloadFolder)) {
  14. New-Item -ItemType Directory -Path $downloadFolder | Out-Null
  15. }
  16. Invoke-WebRequest -Uri $downloadUrl -OutFile $savePath
  17. Write-Host "Le fichier a été téléchargé avec succès dans le dossier Altinea."
  18. # Exécuter le script téléchargé
  19. Write-Host "Exécution du script téléchargé..."
  20. & $savePath
  21. $taskName = "AltiCSInstall"
  22. $scriptPath = "C:\altinea\install\$filepath"
  23. # Vérifier si la tâche planifiée existe déjà
  24. $existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
  25. if ($existingTask -eq $null) {
  26. # Créer un déclencheur pour le démarrage de l'ordinateur
  27. $trigger = New-ScheduledTaskTrigger -AtStartup
  28. # Créer une action pour exécuter le script PowerShell
  29. $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File `"$scriptPath`""
  30. # Créer une tâche planifiée
  31. Register-ScheduledTask -TaskName $taskName -Trigger $trigger -Action $action -User "SYSTEM"
  32. Write-Host "La tâche planifiée '$taskName' a été créée avec succès."
  33. } else {
  34. Write-Host "La tâche planifiée '$taskName' existe déjà."
  35. }