Here i execute power shell Scripts by using in C#:
PSCredential psc = new PSCredential(@"domainname\username", SecurePswd);
WSManConnectionInfo wsmConn = new WSManConnectionInfo(new Uri(strSystemURI), strShellURI, psc);
Runspace rs = RunspaceFactory.CreateRunspace(wsmConn);
rs.open();
String Script = " Get-Mailbox adminuser Select-Object name,primarysmtpaddress, DisplayName,Database,@{e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}";
Pipeline pl = rs.CreatePipeline();
pl.Commands.AddScript(Script);
Collection<PSObject> psCol = pl.Invoke();//Here for me the error occurs "Script block literals are not allowed in restricted language mode or a Data section"
If any knows why this occurs..Tel me..Thanks a lot.