# # # PowerShell 2 # # Update buildings in ServiceView # # # URL to connect to ServiceView # $serviceview_api = "http:///update_buildings.php" # # The value of the SECRET option set in the options setup section. # $serviceview_secret = "" # # Remove buildings not included in this post # $remove_others = "0" # # Build the connect URL # $url = "$($serviceview_api)?secret=$($serviceview_secret)&remove_others=$($remove_others)" # # Load the JSON encoder/decoder # [System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") $ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer # # Create Web Client # $wc = New-Object Net.WebClient # # Connect to ServiceView and download the JSON # $data = @( @{"name"="Buulding 1"; "reference"="loc:1234"} @{"name"="Building 2"; "reference"="loc:12345"} ) # end of data array # # Convert data array into JSON # $json = $ser.Serialize($data) # # Setup the POST values # $nvc = new-object System.Collections.Specialized.NameValueCollection $nvc.Add('data',$json) # # Create a web client object # $wc = new-object net.webclient # # Pass in URL and POST data # $webpage = $wc.UploadValues($url, $nvc) # # See what came back # $ret = [System.Text.Encoding]::ASCII.GetString($webpage) echo $ret