【问题标题】:How can I convert this PowerShell script to create a simple URL in to C# code?如何将此 PowerShell 脚本转换为 C# 代码中的简单 URL?
【发布时间】:2018-04-15 14:26:24
【问题描述】:

我花了一些时间在 PowerShell 中创建它,只是意识到我需要在 C# 中使用一个简单的 EXE 来执行此操作,该 EXE 将创建此 URL 并将浏览器启动到该 URL。基本上它是从 AD 中获取本地登录用户的电子邮件地址和他们的计算机名称,然后使用 JSON 将其提交到另一个表单。

    $email = ([adsi]"LDAP://$(whoami /fqdn)").mail  
    $workstation =  $env:computername

    $url = 'https://www.cognitoforms.com/SupportRequestForm?entry={{"CreateSupportTicket":{{"Workstation":"{0}","YourEmailAddress":"{1}","ConfirmEmail":"{1}"}}}}' -f $workstation, $email.value

有人可以帮我把它转换成 C# 吗?

【问题讨论】:

    标签: c# powershell active-directory


    【解决方案1】:

    我没有在此处安装用于测试的 Active Directory,但我希望这能有所帮助。对于初学者,在解决方案资源管理器的引用节点中添加对 System.DirectoryServices.AccountManagement 的引用,然后在代码中包含 using System.DirectoryServices.AccountManagement;。然后试试这段代码:

    string email = UserPrincipal.Current.EmailAddress;
    string url = string.Format("https://www.cognitoforms.com/SupportRequestForm?entry={{\"CreateSupportTicket\":{{\"Workstation\":\"{0}\",\"YourEmailAddress\":\"{1}\",\"ConfirmEmail\":\"{1}\"}}}}", Environment.MachineName, email);
    Console.WriteLine(url);
    

    如果你需要 fqdn 使用这个:

    string fdqn = System.Net.Dns.GetHostEntry(Environment.MachineName).HostName;
    

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      相关资源
      最近更新 更多