PowerShell版本2调用WebRequest

PowerShell版本2调用WebRequest,powershell,powershell-2.0,powershell-3.0,invoke,Powershell,Powershell 2.0,Powershell 3.0,Invoke,我需要运行包含以下语法的Powershell脚本。这条线的PowerShell 2等价物是什么 Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=Inheritscheduledependency&value=0&username=$User&passhash=$Hash" | out-null 这是完整的脚本: param([int]$Id = 5557,[int]$

我需要运行包含以下语法的Powershell脚本。这条线的PowerShell 2等价物是什么

Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=Inheritscheduledependency&value=0&username=$User&passhash=$Hash" | out-null
这是完整的脚本:

param([int]$Id = 5557,[int]$Duration = 1,[string]$Unit = "Hours")

$Server     = "webpage.bla.org"
$User       = "user"
$Hash       = "45093450908"
$DateFormat     = "yyyy-MM-dd-HH-mm-ss";
$StartDate  = (Get-Date).ToString($DateFormat);

switch($Unit){
"Minutes"   { $EndDate = (Get-Date).AddMinutes($Duration).ToString($DateFormat); }
"Hours"     { $EndDate = (Get-Date).AddHours($Duration).ToString($DateFormat); }
"Days"      { $EndDate = (Get-Date).AddDays($Duration).ToString($DateFormat); }
default     { $EndDate = (Get-Date).AddHours($Duration).ToString($DateFormat); }
}

Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=Inheritscheduledependency&value=0&username=$User&passhash=$Hash" | out-null
Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=maintenable&value=1&username=$User&passhash=$Hash" | out-null
Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=maintstart&value=$StartDate&username=$User&passhash=$Hash" | out-null
Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=maintend&value=$EndDate&username=$User&passhash=$Hash" | out-null

谢谢

在Powershell 2中,您可以使用.NET WebClient类,正如@KIM Taegyoon在一个关于Powershell和webrequests的老问题中指出的那样。看到他的答案了吗

简言之:

(New-Object System.Net.WebClient).DownloadString("http://stackoverflow.com")

在Powershell 2中,您可以使用.NET WebClient类,正如@KIM Taegyoon在一个关于Powershell和webrequests的老问题中指出的那样。看到他的答案了吗

简言之:

(New-Object System.Net.WebClient).DownloadString("http://stackoverflow.com")
可能的重复可能的重复