Skip to content

Instantly share code, notes, and snippets.

@belotn
Last active December 26, 2015 18:59
Show Gist options
  • Save belotn/7198387 to your computer and use it in GitHub Desktop.
Save belotn/7198387 to your computer and use it in GitHub Desktop.
Scheduled Remote Install with Citrix Scheduled Reboot
#########################################################
# FileName RemoteInstall.ps1 #
# Version 0.3 #
# Author Nicolas #
#########################################################
# ChangeLog #
# #
# Version 0.3 #
# Author Nicolas #
# Content Utilisation d'un fichier XML
# pour stocker les actions #
# #
# Version 0.2 #
# Author Nicolas #
# Content Ajout d'un système de multi #
# installation de composant "Actions List" #
# #
# Version 0.1 #
# Author Nicolas #
# Content Initial Realase #
#########################################################
# TODO #
# WSUS Forced Install #
#########################################################
#Chargement des Actions depuis le fichier action_list.xml
([xml]( gc .\action_list.xml)).actions.action |% { new-variable -Name $_.name -value $_ }
#Déploiement
#Ajout des composant Citrix si non chargé
If ((Get-PSSnapin -Name "Citrix*" -ErrorAction SilentlyContinue | Measure-Object).count -eq 0) {Add-PSSnapin -Name "Citrix*"}
Write-host Installation
import-csv .\Folders.txt -delim ';' |% {
#Récupération de la liste des serveurs qui vont redemarrer dans 1h
$servers = get-xaserver -FolderPath $_.Folder |Select ServerNAme,@{N="Last reboot";E={(get-date).AddSeconds( - (gwmi -ComputerName $_.ServerNAme Win32_PerfFormattedData_PerfOS_System).systemuptime) }} |? { $_.'Last Reboot'.dayOfweek -eq [DateTime]::Now.AddDays(-7).DayOfWeek }
$action = $_.action
if( $servers -and (Get-Variable |? { $_.NAme -eq $action })){#L'action existe ?
$myAction = get-variable $action -valueonly
$servers |% {
Write-host $_.ServerName
#copie des fichiers nécessaire
if( -not (test-path \\$($_.serverName)\c$\tmp )){ new-item \\$($_.serverName)\c$\tmp -type directory}
if( $myAction.file ){
cpi $myAction.file \\$($_.serverName)\c$\tmp
}
#lancement de l'installation
$process = [WMICLASS]"\\$($_.ServerName)\ROOT\CIMV2:win32_process"
$result = $process.Create($myAction.script)
}
#temporisation
Start-Sleep -second 120
Write-host suppression
$servers |% {
Write-host $_.ServerName
if( $myAction.clean ){
#Attente de la fin d'installation
while( -not( Select-String \\$($_.ServerNAme)\c$\tmp\$($myAction.clean[0]) -pattern ($myAction.clean[1]) -quiet )){
Start-Sleep -second 120
}
#Suppression des fichiers copiés
if( (get-variable $action -valueonly).file ){
remove-item \\$($_.ServerNAme)\c$\tmp\$( Split-PAth -Leaf $myAction.file )
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment