Transition from Powershell to C# code