Bonjour,
J'ai un script que j'execute et qui m'ouvre une session sur un ordinateur distant. Malgré la fermeture de ma session après chaque lancement, il semblerait que celle-ci reste ouverte.
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
|
Function Get_Information
{
[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[Windows.Forms.MessageBox]::Show(“$Information”, “Delivery Package Perspective”,`
[Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Information)
}
#get-process | out-file -filepath C:\2_Echanges\AA_Powershell\erreur23102015.txt
#Test Connexion à la machine distante
#################################################################
Function Get-password_En_ligne {
$ServeurDistant1="PLUTON"
$login="adlacroix\ADMPLUTON"
$credential = Get-Credential "adlacroix\ADMPLUTON"
$error.Clear()
$session = New-PSSession -computername $ServeurDistant1 -credential $credential
$CodeRetourSession=$?
if ( "$CodeRetourSession" -eq "False" ) { $Information="Attention ! $Error[0]" ; Get_Information }
if ( "$CodeRetourSession" -eq "True" ) {
$error.Clear()
$command = {get-service -Name WinRM}
$res = Invoke-Command -session $session -scriptblock $command
$CodeRetourCommand=$?
if ( "$CodeRetourCommand" -eq "True" ) {
foreach($item in $res){
Write-Host("Nom complet: " + $item.DisplayName)
Write-Host("Name: " + $item.Name)
Write-Host("Etat: " + $item.Status)
Write-Host "Ok"
Remove-PSSession -name $session
}
}
else {
$Information="Test connection ! $Error[0]"
Get_Information
}
}
} |
J'ai le message d'erreur suivant et plus je n'ai que 3 session d'ouverte, pourtant je fais en sorte de toujours la fermer dans mon script
New-PSSession : [PLUTON] La connexion au serveur distant PLUTON a échoué avec le message d’erreur suivant: Le service Gestion des services
Web ne peut pas traiter la demande. Cet utilisateur est autorisé à utiliser un nombre maximal de 5 shells simultanés, valeur qui a été
dépassée. Fermez les shells existants ou augmentez le quota pour cet utilisateur. Pour plus d'informations, voir la rubrique d'aide
about_Remote_Troubleshooting.
Au caractère C:\2\23102015_test.ps1:19 : 16
+ $session = New-PSSession -computername $ServeurDistant1 -credential $credent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108123,PSSessionOpenFailed
je suis alors obligé de réaliser un remove-pssession -name Session2
Merci pour votre aide
Partager