1 powershell invoke powershell-2.0 powershell-3.0
我需要运行一个Powershell脚本,其中包含以下语法.这条线的PowerShell 2相当于什么?
Invoke-WebRequest "http://$Server/api/setobjectproperty.htm?id=$Id&name=Inheritscheduledependency&value=0&username=$User&passhash=$Hash" | out-null
Run Code Online (Sandbox Code Playgroud)
这是完整的脚本:
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
Run Code Online (Sandbox Code Playgroud)
谢谢
Rod*_*ant 15
在Powershell 2中,您可以使用.NET WebClient类,因为@KIM Taegyoon在一个关于PowerShell和webrequests的旧问题中指出了这一点.在这里看到他的答案
简而言之:
(New-Object System.Net.WebClient).DownloadString("http://stackoverflow.com")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11528 次 |
| 最近记录: |