gpt4 book ai didi

powershell - PowerShell版本2调用WebRequest

转载 作者:行者123 更新时间:2023-12-03 00:21:47 25 4
gpt4 key购买 nike

我需要运行其中包含以下语法的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的旧问题中指出的那样。看到他的答案here

简而言之:

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

关于powershell - PowerShell版本2调用WebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30219757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com