Created
May 15, 2018 14:07
-
-
Save Jugulaire/fb186b3038dee33e96821489369b5c2b to your computer and use it in GitHub Desktop.
Random Code Sharing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################################## | |
# Script de publication de site IIS | |
# Todo : | |
# Decoupage en fonctions | |
# TRy-catch sur le parametrage du pool | |
# Dynamisation des messages write-host | |
############################################################################################## | |
Import-Module WebAdministration #Inclure le module de gestion IIS | |
Write-Host "##################################################################################" | |
Write-Host "Script de création de configuration IIS" | |
Write-Host "Un prompt interactif va vous accompagner dans la publication de votre application" | |
Write-Host "Ce script est experimental et doit donc être utilisé avec rigeur !" | |
Write-Host "##################################################################################" | |
$AppName = Read-Host -Prompt "Nom de l'application web" | |
$Port = Read-Host -Promp "Port de publication de l'application" | |
$Path = Read-Host -Prompt "Chemin vers le site web" | |
$Ok = Read-Host "Vous allez publier le site '$AppName' situé dans '$Path' sur le port '$Port' [Y/N]" | |
Write-Host "##################################################################################" | |
Write-Host "Paramétrage du pool d'app :" | |
Write-Host "##################################################################################" | |
$bit = Read-Host "Voulez vous activer les applications 32 bits ? [Y/N]" | |
$mode = Read-Host "Mode du pipeline ? [classic = 1 / integrated = 2 ]" | |
$clr = Read-Host "Version du CLR.NET ? [2/4]" | |
$delais = Read-Host "Delais d'inactivité en minutes ?" | |
$ping = Read-Host "Activé le ping ? [Y/N]" | |
$Recyclage = Read-Host "Heure du recyclage [HH:MM:SS] ?" | |
#Par défaut on set l'intervale de temps a zero | |
If($Ok -like "Y") | |
{ | |
#Cree pool de notre app | |
Write-Host "Création du pool du pool d'app" | |
try { | |
New-WebAppPool $AppName -Force | |
Write-Host "DONE !" | |
}catch { | |
Write-Host "Erreur de création du pool..." | |
exit | |
} | |
#Cree le site web DANS LE POOL | |
Write-Host "Création du site web dans le pool" | |
try { | |
New-Website -Name $AppName -PhysicalPath $Path -Port $Port -ApplicationPool $AppName | |
Write-Host "DONE !" | |
} catch { | |
Write-Host "Erreur création du site..." | |
exit | |
} | |
Write-Host "App 32 bits ..." | |
#Modification des parametres du pool | |
#App 32 bits | |
If ($bit -like 'Y') | |
{ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name enable32BitAppOnWin64 -Value 'True' | |
} ELseif ($bit -like 'N'){ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name enable32BitAppOnWin64 -Value 'False' | |
} | |
Write-Host "DONE !" | |
#mode pipeline | |
Write-Host "Mode Pipeline ..." | |
If ($mode -like '1') | |
{ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name managedPipelineMode -Value 'Classic' | |
} ELseif ($mode -like '2'){ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name managedPipelineMode -Value 'Integrated' | |
} | |
Write-Host "DONE !" | |
#version framework | |
Write-Host "Version du framework ..." | |
If ($clr -like '2') | |
{ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name managedRuntimeVersion -Value 'v2.0' | |
} ELseif ($clr -like '4'){ | |
Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name managedRuntimeVersion -Value 'v4.0' | |
} | |
Write-Host "DONE !" | |
#delais inactivité | |
Write-Host "Delais d'inactivité ... " | |
$ts = [timespan]::FromMinutes($delais) | |
$ts="{0:HH\:mm\:ss}" -f [datetime]$ts.Ticks | |
Set-ItemProperty IIS:\AppPools\$AppName\ -Name processModel.idleTimeout -Value $ts | |
Write-Host "DONE !" | |
#ping | |
Write-Host "Ping ..." | |
$pool = Get-Item IIS:\AppPools\$AppName\ | |
If ($bit -like 'Y') | |
{ | |
$pool.processModel.pingingEnabled = 'True' | |
#Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name processModel.PingingEnabled -Value 'True' | |
} ELseif ($bit -like 'N'){ | |
#Set-ItemProperty -Path IIS:\AppPools\$AppName\ -Name processModel.PingingEnabled -Value 'False' | |
$pool.processModel.pingingEnabled = 'False' | |
} | |
$pool | Set-Item | |
Write-Host "DONE !" | |
#recyclage | |
Write-Host "Recyclage ..." | |
Set-ItemProperty IIS:\AppPools\$AppName\ -Name Recycling.periodicRestart.time -Value '00:00:00' | |
$Recyclage = $Recyclage -as [datetime] | |
$Recyclage = '{0:HH\:mm\:ss}' -f [datetime]$Recyclage | |
Set-ItemProperty IIS:\AppPools\$AppName\ -Name Recycling.periodicRestart.schedule -Value @{value=$Recyclage} | |
Write-Host "DONE !" | |
#Affichage des parametres du pool | |
Get-ItemProperty IIS:\AppPools\$AppName | select * | |
} | |
Else | |
{ | |
Write-Host "ByeBye !" | |
exit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment