I want to automate my Database creation. there are three Databases to create, I have a different powershell script for each DB creation. Now upon this powershell script i have one more layer batch file this batch file will invokes powershell script.
say  @"D:\Parent\Sub\InstallDB1.cmd"; will invoke @"D:\Parent\Powerscript1.ps1 like wise two other. 
Now i have single batch file say FinalDB.cmd. The batch file FinalDB.cmd. will invoke three command scripts one after the other will internally call powershell script.
So now the calls in `FinalDB.cmd`
             call  InstallDB1.cmd  //comment: which internally calls Powerscript1.ps1.
             call  InstallDB2.cmd  //comment: which internally calls Powerscript2.ps1.
             call  InstallDB3.cmd  //comment: which internally calls Powerscript3.ps1.
I cant avoid the above scenario because of my application design.
If I run the Final script manually by double clicking, the DB creation process happening without any fail.But failing when i use following C# code to invoke the FinalDB.cmd.
 public static RunCommand RunCommandInDir(string workingDirectory, string arguments, string executablePath)
    {
        RunCommand runResults = new RunCommand
        {
            Output = new StringBuilder(),
            Error = new StringBuilder(),
            RunException = null
        };
        try
        {
            using (Process proc = new Process())
            {
                proc.StartInfo.FileName = executablePath;
                proc.StartInfo.Arguments = arguments;
                proc.StartInfo.WorkingDirectory = workingDirectory;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError = true;
                proc.StartInfo.CreateNoWindow = false;
                proc.OutputDataReceived +=
                    (o, e) => runResults.Output.Append(e.Data).Append(Environment.NewLine);
                proc.ErrorDataReceived +=
                    (o, e) => runResults.Error.Append(e.Data).Append(Environment.NewLine);
                proc.Start();
                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();
                proc.WaitForExit();
                runResults.ExitCode = proc.ExitCode;
            }
        }
        catch (Exception e)
        {
            runResults.RunException = e;
        }
        return runResults;
    }
When i invoke using the above code i am getting the error "Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program", which was not happening when i run my FinalDB.cmd file manually.
I have done the my googling it seems none of the suggested approaches are working.
Any help to fix the issue?Why does the error is coming when i use C# code.
thanks
 
     
     
    