Ported the PowerShell to csharp