« PowerShell » : différence entre les versions

Aller à la navigation Aller à la recherche
Ligne 77 : Ligne 77 :
#################### - VARIABLES - ####################
#################### - VARIABLES - ####################
$logiciel = @(
$logiciel = @(
 
  [pscustomobject]@{nom="7Zip";path="C:\Support\7zip\7z2201-x64.exe"}
[pscustomobject]@{nom="7Zip";path="C:\Support\7zip\7z2201-x64.exe"}
  [pscustomobject]@{nom="VLC";path="C:\Support\VLC\vlc-3.0.17.4-win64.exe"}
[pscustomobject]@{nom="VLC";path="C:\Support\VLC\vlc-3.0.17.4-win64.exe"}
  [pscustomobject]@{nom="Adobe";path="C:\Support\AdobeXI\AcroRdrDC2101120039_fr_FR.exe"}
[pscustomobject]@{nom="Adobe";path="C:\Support\AdobeXI\AcroRdrDC2101120039_fr_FR.exe"}
  [pscustomobject]@{nom="BgInfo";path="C:\Support\BgInfo\setup-BGInfo4.27.exe"}
[pscustomobject]@{nom="BgInfo";path="C:\Support\BgInfo\setup-BGInfo4.27.exe"}
  [pscustomobject]@{nom="Bureau Distant";path="C:\Support\Bureau distant\setup-bureau distant-v202211.exe"}
[pscustomobject]@{nom="Bureau Distant";path="C:\Support\Bureau distant\setup-bureau distant-v202211.exe"}
  )
)


#################### - SCRIPT - ####################   
#################### - SCRIPT - ####################   
$continue = $true
$continue = $true
while ($continue){
While ($continue) {
 
  Write-Host "-------------------- Logiciel --------------------" -ForegroundColor Cyan
write-host "-------------------- Logiciel --------------------"-ForegroundColor Cyan
  Write-Host "> 1 --->" $logiciel[0].nom -ForegroundColor Cyan
write-host "> 1 --->" $logiciel[0].nom -ForegroundColor Cyan
  Write-Host "> 2 --->" $logiciel[1].nom -ForegroundColor Cyan
write-host "> 2 --->" $logiciel[1].nom -ForegroundColor Cyan
  Write-Host "> 3 --->" $logiciel[2].nom -ForegroundColor Cyan
write-host "> 3 --->" $logiciel[2].nom -ForegroundColor Cyan
  Write-Host "> 4 --->" $logiciel[3].nom -ForegroundColor Cyan
write-host "> 4 --->" $logiciel[3].nom -ForegroundColor Cyan
  Write-Host "> 5 --->" $logiciel[4].nom -ForegroundColor Cyan
write-host "> 5 --->" $logiciel[4].nom -ForegroundColor Cyan
  Write-Host "> all ---> Installation de tous les logiciels de la liste"-ForegroundColor Cyan
write-host "> all ---> Installation de tous les logiciels de la liste"-ForegroundColor Cyan
  Write-Host "--------------------------------------------------" -ForegroundColor Cyan
write-host "--------------------------------------------------"-ForegroundColor Cyan
  Write-Host "Sélectionne une option ou un type" -NoNewline
Write-Host "Select an option or type" -NoNewline
  Write-Host " [quit] " -ForegroundColor Yellow -NoNewline
Write-Host " [quit] " -ForegroundColor Yellow -NoNewline
  Write-Host "to exit : " -NoNewline
Write-Host "to exit: " -NoNewline
  $choix = Read-Host
$choix = Read-Host
  Switch ($choix) {
  switch ($choix)
      "1" {
  {
        Write-Host "Installation de"$logiciel[0].nom"sur le poste"
    "1"
        Start-Process -FilePath $logiciel[0].path -ArgumentList "/S" -NoNewWindow -Wait
    {
        }
      Write-Host "Installation de"$logiciel[0].nom"sur le poste"
      Start-Process -FilePath $logiciel[0].path -ArgumentList "/S" -NoNewWindow -Wait
    }


    "2"
      "2" {
    {
          Write-Host "Installation de"$logiciel[1].nom"sur le poste"
      Write-Host "Installation de"$logiciel[1].nom"sur le poste"
          Start-Process -FilePath $logiciel[1].path -ArgumentList "/S" -NoNewWindow -Wait
      Start-Process -FilePath $logiciel[1].path -ArgumentList "/S" -NoNewWindow -Wait
          }
    }


    "3"
      "3" {
    {
          Write-Host "Installation de"$logiciel[2].nom"sur le poste"
      Write-Host "Installation de"$logiciel[2].nom"sur le poste"
          Start-Process -FilePath $logiciel[2].path -ArgumentList "/S" -NoNewWindow -Wait
      Start-Process -FilePath $logiciel[2].path -ArgumentList "/S" -NoNewWindow -Wait
          }
    }


    "4"
      "4" {
    {
          Write-Host "Installation de"$logiciel[3].nom"sur le poste"
      Write-Host "Installation de"$logiciel[3].nom"sur le poste"
          Start-Process -FilePath $logiciel[3].path -ArgumentList "/S" -NoNewWindow -Wait
      Start-Process -FilePath $logiciel[3].path -ArgumentList "/S" -NoNewWindow -Wait
          }
    }


    "5"
      "5" {
    {
          Write-Host "Installation de"$logiciel[4].nom"sur le poste"
      Write-Host "Installation de"$logiciel[4].nom"sur le poste"
          Start-Process -FilePath $logiciel[4].path -ArgumentList "/S" -NoNewWindow -Wait
      Start-Process -FilePath $logiciel[4].path -ArgumentList "/S" -NoNewWindow -Wait
          }
    }


    "all"  
      "all" {
    {
          Write-Host "Installation de"$logiciel[0,1,2,3,4].nom"sur le poste"
      Write-Host "Installation de"$logiciel[0,1,2,3,4].nom"sur le poste"
          Start-Process -FilePath $logiciel[0,1,2,3,4].path -ArgumentList "/S" -NoNewWindow -Wait
      Start-Process -FilePath $logiciel[0,1,2,3,4].path -ArgumentList "/S" -NoNewWindow -Wait
          }
    }


    "quit"  
      "quit" {
    {
          $continue = $false
    $continue = $false
          }
    }


     default {Write-Host "Choix invalide"-ForegroundColor Red}
     default {Write-Host "Choix invalide" -ForegroundColor Red}
   }
   }
}
}

Version du 18 septembre 2023 à 21:03

PowerShell est un langage de programmation pour les systèmes Microsoft Windows.

Référence

IT-Connect

Marie Pascal Delamare

Site de Marie Pascal Delamare, BTS SIO / STS SIO

Youtube

John Savill's Technical Training, chaîne Youtube

TechSnips by ATA Learning, chaine Youtube, sélection "Doing anything with PowerShell", 334 vidéos au 29/05/2023 :

TechThoughts, chaine Youtube, 41 vidéos au 11/06/2023 :

Document

Gestion des path sous PowerShell, PDF, 31 pages :

Source de script

Gérer les autorisations NTFS avec PowerShell :

Copie de fichiers avec BITS (Background Intelligent Transfer Service) :

PowerShell : convertir PS1 en EXE ; création d'un exécutable :

Interface graphique

Windows10Debloater

Script si problème mise à jour Windows

Le service "Windows Update" s'appelle wuauserv :

  • Stop-Service -Name wuauserv
  • Start-Service -Name wuauserv
  • Set-Service -Name wuauserv -StartupType Automatic
  • Set-Service -Name wuauserv -StartupType Manual
  • Set-Service -Name wuauserv -StartupType Disabled

Impression

Supprimer toutes les fichiers des files d'attente d'impression :

Stop-Service Spooler 
Remove-Item "C:\Windows\System32\spool\PRINTERS\*.*" -Force 
Start-Service Spooler

Autre

Logiciel menu

#################### - VARIABLES - ####################
$logiciel = @(
   [pscustomobject]@{nom="7Zip";path="C:\Support\7zip\7z2201-x64.exe"}
   [pscustomobject]@{nom="VLC";path="C:\Support\VLC\vlc-3.0.17.4-win64.exe"}
   [pscustomobject]@{nom="Adobe";path="C:\Support\AdobeXI\AcroRdrDC2101120039_fr_FR.exe"}
   [pscustomobject]@{nom="BgInfo";path="C:\Support\BgInfo\setup-BGInfo4.27.exe"}
   [pscustomobject]@{nom="Bureau Distant";path="C:\Support\Bureau distant\setup-bureau distant-v202211.exe"}
   )

#################### - SCRIPT - ####################  
$continue = $true
While ($continue) {
   Write-Host "-------------------- Logiciel --------------------" -ForegroundColor Cyan
   Write-Host "> 1 --->" $logiciel[0].nom -ForegroundColor Cyan
   Write-Host "> 2 --->" $logiciel[1].nom -ForegroundColor Cyan
   Write-Host "> 3 --->" $logiciel[2].nom -ForegroundColor Cyan
   Write-Host "> 4 --->" $logiciel[3].nom -ForegroundColor Cyan
   Write-Host "> 5 --->" $logiciel[4].nom -ForegroundColor Cyan
   Write-Host "> all ---> Installation de tous les logiciels de la liste"-ForegroundColor Cyan
   Write-Host "--------------------------------------------------" -ForegroundColor Cyan
   Write-Host "Sélectionne une option ou un type" -NoNewline
   Write-Host " [quit] " -ForegroundColor Yellow -NoNewline
   Write-Host "to exit : " -NoNewline
   $choix = Read-Host
   Switch ($choix) {
      "1" {
         Write-Host "Installation de"$logiciel[0].nom"sur le poste"
         Start-Process -FilePath $logiciel[0].path -ArgumentList "/S" -NoNewWindow -Wait
         }

       "2" {
          Write-Host "Installation de"$logiciel[1].nom"sur le poste"
          Start-Process -FilePath $logiciel[1].path -ArgumentList "/S" -NoNewWindow -Wait
          }

       "3" {
          Write-Host "Installation de"$logiciel[2].nom"sur le poste"
          Start-Process -FilePath $logiciel[2].path -ArgumentList "/S" -NoNewWindow -Wait
          }

       "4" {
          Write-Host "Installation de"$logiciel[3].nom"sur le poste"
          Start-Process -FilePath $logiciel[3].path -ArgumentList "/S" -NoNewWindow -Wait
          }

       "5" {
          Write-Host "Installation de"$logiciel[4].nom"sur le poste"
          Start-Process -FilePath $logiciel[4].path -ArgumentList "/S" -NoNewWindow -Wait
          }

       "all" {
          Write-Host "Installation de"$logiciel[0,1,2,3,4].nom"sur le poste"
          Start-Process -FilePath $logiciel[0,1,2,3,4].path -ArgumentList "/S" -NoNewWindow -Wait
          }

       "quit" {
          $continue = $false
          }

    default {Write-Host "Choix invalide" -ForegroundColor Red}
  }
}

Voir aussi

  •