Hi there I thought I would love some help. no matter how hard I Google, and read Endless amout of information this is just not working. I keep hitting a wall with PowerShell, RunSpace and Pipeline. GORAMIT! sorry just getting frustrated.
Right this is my code that i am trying to get working
String fileServer = servers;
String exePath = "File path with two \\ for the 1 \ due to it being an exit other wise";
String folder = ou1;
String subFolder = ou2;
String root = "root path";
String path = "$" + root + "\\" + ou1 + "\\" + ou2;
String template = " another thing that is needed";
String command = "Invoke-Command-computer $" + fileServer + " -ArgumentList $" + exePath + ",$" + path + ",$" + template + "
-ScriptBlock {param($" + exePath + ",$" + path + ",$" + template + ") & $" + exePath + "\\dirquota.exe autoquota add /path:$" + path + " /sourcetemplate:$" +
template + "}";
using (Runspace script = RunspaceFactory.CreateRunspace())
{
script.Open();
using (Pipeline pipeline = script.CreatePipeline(command))
{
pipeline.Invoke();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException + ex.Message + ex.StackTrace + "\n3" + "powerShell" + DateTime.Now);
}
I'm sure i'm doing this all wrong, But i have no clue what I am doing anymore there are so many versions and none exactly what i need and not enough information for me to make the correct calculations.
what the script is supose to do is call a PowerShell script to run on the arguments given. that is use
Invoke-Command-computer $fileServer -ArgumentList $exePath ,$path,$template -ScriptBlock {param($exePath ,$path , $template)& $exePath\dirquota.exe autoquota add /path:$path /sourcetemplate:$template };
now i given you what i need to do for what the scrip needs to do what it does but how do i do it?
as you see i'm failing miserably at this I have never worked with power shell scripts in C# before and it seems to
error every time the error i am getting is
Missing ')' in function parameter list. at System.Management.Automation.Parser
.ReportException(Object targetObject, Type exceptionType, Token errToken, String
resourceIdAndErrorId, Object[] args)
at System.Management.Automation.Tokenizer.Require(TokenId tokenId, String res
ourceIdAndErrorId, Object[] args)
at System.Management.Automation.Parser.ParameterDeclarationRule(Boolean isPar
ameterStatement, Token startScriptBlock, List`1& parameterComments)
at System.Management.Automation.Parser.ScriptBlockRule(String name, Boolean r
equireBrace, Boolean isFilter, ParameterDeclarationNode parameterDeclaration, Li
st`1 functionComments, List`1 parameterComments)
at System.Management.Automation.Parser.SubScriptblockRule()
at System.Management.Automation.Parser.ValueRule()
at System.Management.Automation.Parser.CompoundValueRule()
at System.Management.Automation.Parser.commandRule()
at System.Management.Automation.Parser.PipelineRule()
at System.Management.Automation.Parser.StatementRule()
at System.Management.Automation.Parser.StatementListRule(Token start)
at System.Management.Automation.Parser.ScriptBlockRule(String name, Boolean r
equireBrace, Boolean isFilter, ParameterDeclarationNode parameterDeclaration, Li
st`1 functionComments, List`1 parameterComments)
at System.Management.Automation.Parser.ParseScriptBlock(String input, Boolean
interactiveInput)
at System.Management.Automation.AutomationEngine.ParseScriptBlock(String scri
pt, Boolean interactiveCommand)
at System.Management.Automation.ScriptCommandProcessor..ctor(String script, E
xecutionContext context, Boolean isFilter, Boolean useLocalScope, Boolean intera
ctiveCommand, CommandOrigin origin)
at System.Management.Automation.Runspaces.Command.CreateCommandProcessor(Exec
utionContext executionContext, CommandFactory commandFactory, Boolean addToHisto
ry)
at System.Management.Automation.Runspaces.LocalPipeline.CreatePipelineProcess
or()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
Any help would be much appreciate PLEASE! if I do happen to stumble upon a solution I will let you know and post it, but the way everything is going and 2 days of research I am pleading in desperation for some help from you wise people out there
Kind regards
Dazhiki
And thanks in advance for any help.
all I need is a Eureka moment