Question Script pour ce mettre à jour lui même

Plus d'informations
il y a 12 ans 8 mois #15292 par smadon
Hello,

je cherche a trouvé la bonne solution pour permetre à mon script de se mettre à jour lui meme.

J'explique :
je vais copier sur chaque pc du réseau un script pcupdater.ps1 qui va mettre à jour le pc.
Par contre, ce script va évoluer dans le temps (surtout pendant les corrections de bug :-)
Et je voudrais que quand l'utilisateur lance ce script que la premiere des taches soit de checker sur le serveur TOTO si il y a une version plus récente.

Voici mon idée de départ mais je ne pas d'autre solution que de creer un fichier temp.

User lance pcupdater.ps1

- Pcupdater.ps1 check connection to TOTO if not message and exit
- Pcupdater.ps1 check pcupdater-temp.ps1 in toto exist if not we don't Update, we give a message and exit
- Pcupdater.ps1 copy pcupdater-temp.ps1 in c drive and run it


Merci pour vos idées.
Smadon

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 8 mois #15293 par Laurent Dardenne
Salut,
consulte ce principe
poshcode.org/2187

Une fois ton script chargé en mémoire tu peux le supprimer, pas besoin de fichier temporaire.Mais cela dépend de ton contexte.

Pour les paramètres, un appel du type :
[code:1].\script.sp1 @PSBoundParameter[/code:1]
devrait suffire.
Reste à déterminer, si besoin, si son exécution c'est faite dans sa propre portée ou dans celle de l'appelant.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 12 ans 8 mois #15295 par smadon
Nikel ca marche.
merci


[code:1]
param(
[Parameter(Mandatory=$True,Position=1)]
[string]$UpdateStatus
)


#Load Library
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\"«») | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Drawing\"«») | Out-Null

$Network = New-Object -ComObject \"Wscript.Network\"
$ShellApps = New-Object -ComObject shell.application


#Variable Parameter
$UpdateFile = \"UPDATEFILE\"
$StartUpdate = \"STARTUPDATE\"



function main {

#....

if((Test-Connection -Cn $NetworkDrive -BufferSize 16 -Count 1 -ea 0 -quiet) -and (Test-Path -Path $PCUpdaterNewFile) ) {
# All Good we can access the $Network drive and file PCUpdaterTemp.ps1 exist


# If Parameter UPDATEFILE
if ( $UpdateStatus -eq $UpdateFile) {
# Copy pcupdater-temp.ps1 in c drive and
Copy-Item -Path $PCUpdaterNewFile -Destination $PCUpdaterPath -Force
# restart PCUpdater.ps1
&$RunningPath\$PCUpdaterFile $StartUpdate
}

# If Parameter STARTUPDATE
if ( $UpdateStatus -eq $StartUpdate) { LogoForm }


# ......
}
[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.076 secondes
Propulsé par Kunena