PowerShell版本2 Invoke-WebRequest

问题描述:

我需要运行一个Powershell脚本,它具有下面的语法。这条线的PowerShell 2相当于什么?PowerShell版本2 Invoke-WebRequest

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 

感谢

+1

的可能重复[HTTP使用PowerShell请求(http://stackoverflow.com/questions/7715695/http-requests-with-powershell) –

在PowerShell中2,你可以使用.NET WebClient类如@KIM Taegyoon约PowerShell和webrequests一个老问题,指出。见他的回答here

简而言之:

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