ClasssLibrary1:Class Public string RunScript(string scriptText) { Runspace runspace = RunspaceFactory.CreateRunspace(); runspace.Open(); Pipeline pipeline = runspace.CreatePipeline(); pipeline.Commands.AddScript(scriptText); pipeline.Commands.Add("Out-String"); Collection<PSObject> results = pipeline.Invoke(); runspace.Close(); StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { stringBuilder.AppendLine(obj.ToString()); } return stringBuilder.ToString(); } public string LoadScript(string filename) { try { using (StreamReader sr = new StreamReader(filename)) { StringBuilder fileContents = new StringBuilder(); string curLine; while ((curLine = sr.ReadLine()) != null) { fileContents.Append(curLine + "\n"); } return fileContents.ToString(); } } catch (Exception e) { string errorText = "The file could not be read:"; errorText += e.Message + "\n"; return errorText; } }
rmdir D:\Logs mkdir D:\Logs Get-EventLog Application |Format-List | Out-File D:\Logs\app.txt Get-EventLog System |Format-List | Out-File D:\Logs\app.txt
Quote:if i deleted the folder which is created during script execution then again it works
rmdir D:\Logs
rmdir
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)