需要从PowerShell脚本调用以下URL:
$webAPIUrl =  "http://hostName:portNumber/test/schedule-process/22/true"
Run Code Online (Sandbox Code Playgroud)
调用异常时抛出"发生错误".
PowerShell脚本:  
Invoke-WebRequest -Uri $webAPIUrl -Method get -UseBasicParsing
Run Code Online (Sandbox Code Playgroud)
使用Postman检查此URL时抛出了相同的异常.
C#API代码:
  public class ScheduleController : ApiController  
  {  
      [HttpGet]  
      public void SchedulingProcess(int scheduleId, bool isScheduleStart)  
      {  
      }  
  }  
Run Code Online (Sandbox Code Playgroud)
路线配置代码:
config.Routes.MapHttpRoute("SchedulingProcess","test/schedule-process/{scheduleId}/{isScheduleStart}",new { controller = "Schedule", action = "SchedulingProcess" });  
Run Code Online (Sandbox Code Playgroud)
从C#调用时工作正常:
string webAPIUrl = "http://hostName:portNumber/test/schedule-process/22/true";
new WebClient().OpenReadAsync(new Uri(webAPIUrl));
Run Code Online (Sandbox Code Playgroud)
请帮我从PowerShell脚本调用此URL.
我已将数据磁盘添加到Azure虚拟机,并且需要为其创建卷。
我已使用以下代码创建该卷:
$disk = Get-Disk | where-object PartitionStyle -eq "RAW"  
$disk | Initialize-Disk -PartitionStyle GPT  
$partition = $disk | New-Partition -UseMaximumSize -DriveLetter F  
$partition | Format-Volume -Confirm:$false -Force  
Run Code Online (Sandbox Code Playgroud)
创建卷时,它会在格式化磁盘之前要求确认。
我想避免此确认框。我尝试过,-Confirm:$false -Force但仍然提示您确认。
需要验证Azure虚拟机用户名和密码.
现在使用以下代码验证虚拟机用户名和密码.
$SecureVmPassword = ConvertTo-SecureString -string $VmPassword -AsPlainText -Force
$VmCredential = New-Object -typename System.Management.Automation.PSCredential -argumentlist $Fqdn"\"$VmUsername, $SecureVmPassword
Invoke-Command -ConnectionUri $RemoteConnectionUri.ToString() -Credential $VmCredential -ScriptBlock{
}  
Run Code Online (Sandbox Code Playgroud)
但是,当虚拟机处于关闭状态时,无法验证虚拟机凭据.
即使虚拟机处于关闭状态,有没有办法验证虚拟机凭据?
我使用以下代码成功获取执行策略:
using (var powerShellInstance = PowerShell.Create())
{
    powerShellInstance.AddCommand("Get-ExecutionPolicy");
    Collection<PSObject> obj = powerShellInstance.Invoke();
}
Run Code Online (Sandbox Code Playgroud)
我使用以下代码来设置执行策略:
using (var powerShellInstance = PowerShell.Create())
{
    powerShellInstance.AddCommand("Set-ExecutionPolicy").AddArgument("ByPass");
    powerShellInstance.Invoke();
}
Run Code Online (Sandbox Code Playgroud)
问题是当我从 PowerShell 设置执行策略时,更改在 C# 中不可见。如果我从 C# 设置执行策略,则更改是可见的。
考虑以下场景:
Unrestricted。Bypass。Unrestricted。Bypass.Bypass。我有一个 mysql 表,我需要使用 C# 用数据表更新它。
我使用以下代码在 sql 中实现了这一点:
DataTable table;
using (SqlConnection connection = new SqlConnection(connectionString))  
{
    connection.Open();
    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
       {
           bulkCopy.DestinationTableName = destinationTable;
           bulkCopy.WriteToServer(table);
       }
 }  
Run Code Online (Sandbox Code Playgroud)
mysql 有没有办法实现这一点?