AutoGRAPH.NET Service Examples Powershell — различия между версиями
Admin (обсуждение | вклад) |
Admin (обсуждение | вклад) |
||
Строка 9: | Строка 9: | ||
"== Prepare and Login ========================================================================" |
"== Prepare and Login ========================================================================" |
||
$c = New-Object -TypeName System.Net.WebClient; |
$c = New-Object -TypeName System.Net.WebClient; |
||
+ | $c.Encoding = [System.Text.Encoding]::UTF8; |
||
$c.Headers.Add("Content-Type", "text/json"); |
$c.Headers.Add("Content-Type", "text/json"); |
||
$token = $c.UploadString("$URL/Login", "{""UserName"":""demo"",""Password"":""demo""}").Trim(""""); |
$token = $c.UploadString("$URL/Login", "{""UserName"":""demo"",""Password"":""demo""}").Trim(""""); |
Версия 09:49, 30 марта 2019
Powershell_Basic.ps1
Нижприведенный файл выполняет несколько запросов и сохраняет их результаты в файлы .CSV
$URL = "http://m.tk-chel.ru:8300"; $SCHEMA = "DemoCEBIT" "" Remove-Item "*.csv" -ErrorAction SilentlyContinue "== Prepare and Login ========================================================================" $c = New-Object -TypeName System.Net.WebClient; $c.Encoding = [System.Text.Encoding]::UTF8; $c.Headers.Add("Content-Type", "text/json"); $token = $c.UploadString("$URL/Login", "{""UserName"":""demo"",""Password"":""demo""}").Trim(""""); $c.Headers.Add("AG-TOKEN", $token) "Token: $token" $token > "PS_Token.csv" "" "== EnumSchemas ==============================================================================" $schemas = $c.DownloadString("$URL/EnumSchemas") | ConvertFrom-Json foreach($x in $schemas) { $x.ID+": "+$x.Name } $schemas | Export-Csv "PS_Schemas.csv" -NoTypeInformation "" "== EnumDevices ==============================================================================" $devices = $c.DownloadString("$URL/EnumDevices/$SCHEMA") | ConvertFrom-Json "Groups: "+$devices.Groups.Length "Devices: "+$devices.Items.Length $devices.Groups | Select-Object ID,ParentID,Name | Export-Csv "PS_Devices_Groups.csv" -NoTypeInformation $devices.Items | Select-Object ID,ParentID,Name,Allowed,Serial | Export-Csv "PS_Devices_Devices.csv" -NoTypeInformation "" "== EnumGeofences ============================================================================" $geofences = $c.DownloadString("$URL/EnumGeofences/$SCHEMA") | ConvertFrom-Json "Groups: "+$geofences.Groups.Length "Devices: "+$geofences.Items.Length $geofences.Groups | Select-Object ID,ParentID,Name | Export-Csv "PS_Geofences_Groups.csv" -NoTypeInformation $geofences.Items | Select-Object ID,ParentID,Name | Export-Csv "PS_Geofences_Geofences.csv" -NoTypeInformation "" "== GetOnlineInfoAll =============================================================" $oi = $c.DownloadString("$URL/GetOnlineInfoAll/$SCHEMA") | ConvertFrom-Json "OnlineInfoItems: "+$oi.Length $oiresult =@() $dt = (Get-Date).ToUniversalTime() foreach($item in $oi) { $obj = New-Object PSObject $obj | Add-Member -MemberType NoteProperty -Name "ID" -Value $item.Key $obj | Add-Member -MemberType NoteProperty -Name "Name" -Value $item.Value.Name if($item.Value) { $obj | Add-Member -MemberType NoteProperty -Name "DTUTC" -Value $item.Value.DT $obj | Add-Member -MemberType NoteProperty -Name "Lat" -Value $item.Value.LastPosition.Lat $obj | Add-Member -MemberType NoteProperty -Name "Lng" -Value $item.Value.LastPosition.Lng $obj | Add-Member -MemberType NoteProperty -Name "State" -Value $item.Value.State $obj | Add-Member -MemberType NoteProperty -Name "Latency" -Value $dt.Subtract($item.Value.DT).TotalMinutes } else { $obj | Add-Member -MemberType NoteProperty -Name "DTUTC" -Value "" $obj | Add-Member -MemberType NoteProperty -Name "Speed" -Value "" $obj | Add-Member -MemberType NoteProperty -Name "Lat" -Value "" $obj | Add-Member -MemberType NoteProperty -Name "Lng" -Value "" $obj | Add-Member -MemberType NoteProperty -Name "State" -Value "" $obj | Add-Member -MemberType NoteProperty -Name "Latency" -Value "" } $oiresult += $obj } $oiresult | Export-Csv "PS_GetOnlineInfoAll.csv" -NoTypeInformation