1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| $DossierScript = Split-Path $MyInvocation.MyCommand.Path
$Dossier_de_Base = Split-Path -Parent $DossierScript
$Nom_du_Script = Split-Path -Leaf $MyInvocation.MyCommand.Definition
$Extension_Script = $Nom_du_Script.SubString( ( $Nom_du_Script.Length )-3,3 )
$Log_Cour = $Dossier_de_Base + "\Logs\" + ( $Nom_du_Script).Replace( $Extension_Script,"txt" )
$List_Script = $Dossier_de_Base + "\Inputs\testcoucou.txt"
$AD_Login = "DOMAINE\USER"
$AD_Pwd = "MotDepasse"
#Création du credential
$SecurePassword = ConvertTo-SecureString $AD_Pwd -AsPlainText -force
$Credential = New-Object System.Management.Automation.PsCredential( $AD_Login, $SecurePassword )
$RemoteSession = New-PSSession -ComputerName "$($Env:COMPUTERNAME).DOMAINE.COM" -Credential $Credential
<#Liste des scripts
------------------#>
Write-host " Lancement du script Général qui ordonnance les différents scripts dédiés à la migration du serveur "
$List = ( Get-Content $List_Script )
ForEach ( $Line In $List )
{ $Line1 = Split-Path -Leaf $Line
Write-host $Line1 -ForegroundColor Yellow
If ( !( Test-Path $Line ) )
{ Write-host "Le script $Line1 est introuvable" -ForegroundColor Red
"Le script $Line1 est introuvable" | Add-Content $Log_Cour
Write-host "Arrêt du script Général" -ForegroundColor Red
"Arrêt du script Général" | Add-Content $Log_Cour
Exit }
Else
{
[int]$Script = 0
write-host "Le script $Line1 est en cours d'execution" -ForegroundColor Green
$Msg1 = "Erreur - L'execution du script $Line1 est en Erreur - Arrêt du script"
$Msg0 = "OK - L'execution du script $Line1 est OK - Lancement du prochain script"
$script = Invoke-Command -session $RemoteSession -filepath $Line
write-host "Le code retour est $script"
}
switch ( $script )
{
1 { Write-Host $Msg1 -ForegroundColor Red
$Msg1 | Add-Content $Log_Cour
Exit }
0 { write-host $Msg0 -ForegroundColor Green
$Msg0 | Add-Content $Log_Cour }
}
}
"fini" | Add-Content $Log_Cour |
Partager