• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Posting an URL with Powershell?


Duncan Smith

Using the new Get-Url Cmdlet from the community extensions, I'm able
to return a chunk of xml from a database, apply an offset to some time
data, and generate an SQL Update command.

Unfortunately, I can't see a Post-Url Cmdlet that would let me post
the SQL back to the SQLXML website that it came from.

In the past I've used the XMLHttpRequest COM object to do this kind of
thing, so I guess there are two questions..

(a) Is there a .NET equivalent of XMLHttpRequest and can it be used
from the Powershell easily enough?

(b) if not, how can I use the old XMLHttpRequest object in the
Powershell script to post data to a web-server?

Any pointers greatly appreciated..



---script so far---
"running .\fixweather.ps1"


# get fridays weather from the database into a DOM
$friStr = "<root>"
$friStr += Get-url "http://barsql01/outingdatabase?sql=exec
F1QryWeatherForEventXML_sp @p_strEvent='03_18Mel',
@p_strSeason='2007', @p_strMinTime='2007-03-15 23:00:00',
@p_strMaxTime='2007-03-16 06:15:00'"
$friStr += "</root>"
[xml]$friXml = $friStr

# pretty-print and write to a file
# fxml -InputObject $fri > fri.xml

# for each weather event/sample
dbo.WeatherEvent[WeatherTime]") |% {
# get the time and uuid from the xml
$time = $_.selectsinglenode('WeatherTime');
$guid = $_.selectsinglenode('WeatherEventID');

# apply the time-diff
[DateTime]$eventTime = $time.get_innerxml();
[DateTime]$adjustedTime = $eventTime.AddHours(10);

# format an SQL update command to apply the time-diff
$updateSQLString = "UPDATE WeatherEvent SET WeatherTime = '{0}'
WHERE WeatherEventID='{1}'" -f $adjustedTime.ToString("yyyy-MM-dd
HH:mm:ss"), $guid.get_innerxml();
echo $updateSQLString.ToString();


My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)