If you have a bat that serves you, and what it does is execute commands, and it has done that, I don't see much advantage in converting to C#.
You would have to learn C#, and write all your commands already porting them to methods and instructions inside C#, and believe me, that will take a long time.
It would have to carry its variables, its commands, the paths of folders/files, accounts and users, credentials, password, in addition to treatments for possible errors (predictable and unpredictable), and this really takes a long time..
There is no converter that does this, however it is possible to "run" a bat in C# and capture the output, or it is also possible to make "calls" for isolated (or not) executions of commands.
As much as I have some remarks in your script, and I won't comment on those, as I understand that it's just an outline to exemplify the question, the only visible reason for your intention would be to omit username/password.
Is this correct? If so, then your question would have either another, you would have to open a specific question in that sense...
Anyway, there are several options without having all this work/time, among them the ones I usually use, I just make the C# generate the bat...
The simplest way to generate a bat, and without wasting a lot of time, already reducing the number of necessary lines in C#, is to:
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
String encodedString = @"QGVjaG8gb2ZmIAoKc2V0ICJ4PUZvbGRlciIKeGNvcHkgL3kgL3YgL2UgLlw
iJXglIlwqIFxcMTAuMC4wLjIwMFxkXAoKZm9yICUleSBpbiAoMjAyLDIwMy
wyMDQsMjA1KWRvICgKICAgICBuZXQgdXNlIFxcMTAuMC4wLiUlfnlcZSAiJ
X4xIiAvdXNlcjoiJX4yIgogICAgIGVjaG9cQ29weWluZyBmaWxlcyB0byBc
XDEwLjAuMC4lJX55XGVcCiAgICAgeGNvcHkgL3kgL3YgL2UgLlwiJXglIlw
qIFxcMTAuMC4wLiUlfnlcZVwKICAgICk=";
File.WriteAllBytes(@"z:\batchfilename.bat", Convert.FromBase64String(encodedString));
System.Diagnostics.Process.Start(@"z:\batchfilename.bat", "\"PassWord1\" \"User1\"");
}
}
}
1. Create your bat and test it as much as possible
2. Convert the code to base64
3. Defines a variable in your code with the base64 strings
4. Decode at runtime to a pre-defined and proper location for execution
5. Call the bat execution on the path where it was decodes
6. If necessary, pass your arguments
For more options and to get output without opening a cmd window, see this answer on
Executing Batch File in C# - Stack Overflow