Partage
  • Partager sur Facebook
  • Partager sur Twitter

Script install désinstall app en powershell

Script install désinstall app en powershell

Sujet résolu
7 août 2019 à 3:51:52

Bonjour

Me voila de retour je viens de realiser un script powershell je suis pas un as d'en le domaine mais je ne pensais pas avoir fait erreur.

Mais malheureusement Powershell me dit que si avec comme message pour la partie désinstallation

Et je ne comprend quel "Bloc d’instruction" est manquant ?

Au caractère C:\Users\Administrateur\Desktop\Install_NotepadPlusPlus.ps1:20 : 80
+ ... v:ProgramFiles(x86)}\Notepad++\uninstall.exe" -PathType Leaf) -or (Te ...
+                                                                 ~
Bloc d’instruction manquant après If ( condition ).
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingStatementBlock


Voici le script :

# Script install App MDT
# ----------- Modifier variable apres cette ligne -----------
# ------------- Modify variable after this line -------------

$NameApp = "Notepad++"
$Installer32 = "Notepad++-7.71\npp.7.7.1.Installer.exe"
$Installer64 = "Notepad++-7.71\npp.7.7.1.Installer.x64.exe"
$arguments = "/S"
$uninstaller32or64 = "Notepad++\uninstall.exe"
$argumentsUninstall = "/S"

# --------------- Ne rien modifier apres cette ligne ---------------
# ------------- Do not modify anything after this line -------------

# Get the TS variables
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$DeployRoot = $tsenv.Value("DeployRoot")

Write-Output "Suppr $NameApp"

If (Test-Path "${env:ProgramFiles(x86)}\Notepad++\uninstall.exe" -PathType Leaf) -or (Test-Path "${Env:ProgramFiles}\Notepad++\uninstall.exe" -PathType Leaf)
{
	If (Test-Path "${env:ProgramFiles(x86)}\$uninstaller32or64" -PathType Leaf)
	{
		$executableSupprFinal = "${env:ProgramFiles(x86)}\$uninstaller32or64"
		start-process $executableSupprFinal $argumentsUninstall -PassThru -Verb RunAs -Wait -NoNewWindow
	}
	If (Test-Path "${Env:ProgramFiles}\$uninstaller32or64" -PathType Leaf)
	{
		$executableSupprFinal = "${env:ProgramFiles}\$uninstaller32or64"
		start-process $executableSupprFinal $argumentsUninstall -PassThru -Verb RunAs -Wait -NoNewWindow
	}
}

Write-Output "Installation $NameApp"

If (Test-Path "${env:ProgramFiles(x86)}")
{
	$Installer = $Installer64
	$InstallerFinal = "$DeployRoot\Applications\$Installer"
	start-process $InstallerFinal $arguments -PassThru -Verb RunAs -Wait -NoNewWindow
}
Else 
{
	$Installer = $Installer32
	$InstallerFinal = "$DeployRoot\Applications\$Installer"
	start-process $InstallerFinal $arguments -PassThru -Verb RunAs -Wait -NoNewWindow
}

#Copy Item from Deployroot
Write-Output "Copie auxiliere $NameApp"

$SourceLanguageNotepadPlusPlus = "$DeployRoot\Applications\Notepad++-7.71\nativeLang.xml"
$SourcePluginNotepadPlusPlus = "$DeployRoot\Applications\Notepad++-7.71\ComparePlugin\*"
$DestinationLanguageNotepadPlusPlus = "C:\users\Default\AppData\Local\Roaming\Notepad++\"
$DestinationPluginNotepadPlusPlus = "C:\Program Files\Notepad++\plugins\ComparePlugin"
Copy-Item -Path $SourceLanguageNotepadPlusPlus -Destination $DestinationLanguageNotepadPlusPlus -Force -Recurse
Copy-Item -Path $SourcePluginNotepadPlusPlus -Destination $DestinationPluginNotepadPlusPlus -Force -Recurse

Write-Output "Fin install $NameApp"



Merci de vos retour.

Si par hasard vous avez des proposition amélioration de script allègement de ligne ou autres hésité pas a me dire.

Edit le 2019-08-07 :

Fichu parenthèse manquant j'avais oublier d'englober met deux conditions voici l'auto correction.

If ((Test-Path "${env:ProgramFiles(x86)}\Notepad++\uninstall.exe" -PathType Leaf) -or (Test-Path "${Env:ProgramFiles}\Notepad++\uninstall.exe" -PathType Leaf))



-
Edité par Vincent1890 7 août 2019 à 17:55:20

  • Partager sur Facebook
  • Partager sur Twitter