1

I'm needing to run a Powershell script that has the below syntax in it. What would be the PowerShell 2 equivalent of this line be?

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

This is the full script:

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

Thanks

1

1 Answer 1

17

In Powershell 2 you could use the .NET WebClient Class as @KIM Taegyoon points out in an older question about PowerShell and webrequests. See his answer here

In short:

(New-Object System.Net.WebClient).DownloadString("http://stackoverflow.com")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.