Bonjour,
J'essaie désespérément depuis des mois de créer une Mailbox Exchange 2010 en C#, à partir d'un compte Active Directory existant.
À chaque fois il y a un erreur quelconque.
Cette fois j'ai cette exception :
"Impossible de valider l'argument sur le paramètre «*Session*». L'argument est null. Indiquez un argument non-null et réessayez."}
Interception de System.Management.Automation.ParameterBindingValidationException
Message="Impossible de valider l'argument sur le paramètre «*Session*». L'argument est null. Indiquez un argument non-null et réessayez."
Source="System.Management.Automation"
J'ai beau chercher toutes les aides possibles et imaginables, tester toutes les solutions proposées, rien ne fonctionne.
Voici ma fonction:
Et la fonction RunScript qui y est appelée :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public String EnableMailbox(string UserAD) { try { String account = "domain\\" + UserAD; String Alias = UserAD; String scriptToRun = "$pwd = ConvertTo-SecureString \"password\" -AsPlainText -Force"; scriptToRun = scriptToRun + "\r $profile = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList \"Admin\", $pwd"; scriptToRun = scriptToRun + "\r $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri Http://SBSERVER2011/powershell/ -Credential $profile"; scriptToRun = scriptToRun + "\r Import-PSSession $session"; scriptToRun = scriptToRun + "\r Enable-MailBox -Identity " + account + " -Alias " + Alias; return RunScript(scriptToRun); } catch (Exception error) { MessageBox.Show(error.ToString()); throw error; } }
Pourriez-vous m'aider SVP !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 /*** Exchange ***/ private string RunScript(string scriptText) { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); // create a pipeline and feed it the script text Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(scriptText); pipeline.Commands.Add("Out-String"); // execute the script Collection<PSObject> results = pipeline.Invoke(); // close the runspace runspace.Close(); // convert the script result into a single string StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { stringBuilder.AppendLine(obj.ToString()); } return stringBuilder.ToString(); }![]()
Partager