我需要运行一个包含以下语法的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谢谢
发布于 2015-05-14 02:02:23
在Powershell2中,你可以使用.NET WebClient类,就像@KIM Taegyoon在一个关于Powershell和webrequests的老问题中指出的那样。查看他的答案here
简而言之:
(New-Object System.Net.WebClient).DownloadString("http://stackoverflow.com")https://stackoverflow.com/questions/30219757
复制相似问题