#ConvertFrom-JSON
Explore tagged Tumblr posts
Text
PostgreSQL, PowerShell and Software Development
PostgreSQL is something else. It's enjoyable, I'm not worried about licensing, and I find everything about PGSQL 16 to be pretty easy to learn, given my background. Their documentation is stellar, and specific questions I might have typically have a presence on the web (usually in a Stack Exchange site).
Over the past few weeks, I migrated a bunch of data from JSON and CSV files I was manipulating via ConvertFrom cmdlets in PowerShell. Moving the data was no problem. PG's COPY command is useful and so is pgAdmin 4. UTF8 versus Windows 1252 text encoding for CLI work was annoying, but only a minor delay. Adapting some of the programmatic features from PowerShell, such as regex replacements, proved more arduous but nothing was spectacularly difficult.
To render some of the data (more than 30,000 rows) into readable text, I made a PS script that rendered the SQL that then rendered single-column CSV results I could then finalize. For that finalization, I ran WSL2 dos2unix and a few sed commands. It was vastly easier to do that than to operate purely in PowerShell or PostgreSQL.
In BeyondCompare 4, I was able to see that my previous text results matched what I was getting from PowerShell, and as a bonus, PG did it in 25% of the time (4 times faster).
My efforts have been lovely exercises in finding and using resources while also finding and NOT utilizing resources. Each step has taken effort and involved a lot of small proof-of-concept and pseudo code before actual development or processing. PowerShell's Select-Object has become my favorite tool to limit data for testing. The smallest effective step is almost always the best step. It's a software development and/or engineering version of Occam's razor.
My next steps are up in the air somewhat. I have an idea of what I want to do with my data and content, but making it happen means thinking about it until the right path reveals itself. This part is most Zen and a bunch of RTFM.
Chances are good that I'll end up with an Express.js app, some client rendering framework (e.g. Angular), and a number of stored procedures or functions in PGSQL that do what I want. Chances are also good that I'm going to index what I'm working against in such a way that text replacement can be as fast as Big-O log(n). That's the goal, operatively, but the real goal is to master what I want to know of Postgres and to expand my knowledge of Node.js and client-side JavaScript (or ECMA).
0 notes
Text
Obtener empresas del IBEX 35 en formato JSON
Obtener empresas del IBEX 35 en formato JSON
[System.Collections.ArrayList] $arraylist = New-Object System.Collections.ArrayList # Obtener empresas del IBEX 35 $web = Invoke-WebRequest 'http://www.bolsamadrid.es/esp/aspx/Mercados/Precios.aspx?indice=ESI100000000' $result = $web.AllElements | Where Class -eq “DifFlBj” | %{$_.innerText} $result += $web.AllElements | Where Class -eq “DifFlSb” | %{$_.innerText} $result += $web.AllElements |…
View On WordPress
#AllElements#ArrayList#Collections#ConvertFrom-JSON#Empresa#foreach#HTTP#IBEX 35#innerText#Invoke-WebRequest#JSON#Mercados#New-Object#PSCustomObject#System.Collections.ArrayList
0 notes
Text
Illustration of an example availability monitoring service Using PowerShell and SQL
Illustration of an example availability monitoring service Using PowerShell and SQL
This article discusses a simple solution of how to monitor SQL service availability across multiple servers and reporting. To build this I’ll use SQL Server with simple PowerShell script and cmdlets which generate JSON data and displays results in HTML Article highlights Defines the objective of JSON Explains the PoSH JSON cmdlets internals and other details on its usage Proactive Monitoring of…
View On WordPress
#CnvertTo-JSON details#Convertfrom-JSON details and examples#JSON constructs for data querying#Monitoring services using JSON
0 notes
Text
Hi peeps. I need some help with #Docker Args being a json string. Within the Docker container I run a #PowerShell script which takes the ARG as parameter. How should the argument look like to be able to use convertfrom-json cmdlet in PowerShell script? https://t.co/vsdxExyLc1
Hi peeps. I need some help with #Docker Args being a json string. Within the Docker container I run a #PowerShell script which takes the ARG as parameter. How should the argument look like to be able to use convertfrom-json cmdlet in PowerShell script? pic.twitter.com/vsdxExyLc1
— Stefan Stranger (@sstranger) February 24, 2020
from Twitter https://twitter.com/sstranger February 24, 2020 at 07:16PM via IFTTT
0 notes
Text
ConvertTo/From-JSON MongoDB
Learning the quirks of powershell has had some benefits and some things that have made me irritated. I got an error that my type could not be put into another type. I’ve got a 3rd party vender that we use for our CRM and we use MongoDB to do some more dynamic signage types of things in our office. In doing this simple pull from one and putting it into another, everything seems fine, except the C# won’t take one field (it has an array, I know why it won’t, but irritating) so I went through some options to try and put the square through the round hole. I tried to flatten, but seems that flattening it wasn’t working, tried to convert it a few times a few different ways in hopes that the converted changes would possibly get it to work. Nothing seemed to work, I spent quite a bit of time and I was ready to attempt some very extreme measures when I thought. What if I converted it to JSON and back through powershell. This is very, very silly to think of working, but sure enough, it worked great.. Well, for my one entry I was pulling at least.
Here is kind of what I had made and got to work, if you have something that works without the JSON conversion, sweet.
Get-Data -Entity DataTable -Filter {idcolumn -eq 5} | ConvertTo-JSON | ConvertFrom-JSON | Add-Mdbc-Data
Now the aha moment was running this and it actually put my array inside of the database and only had one document, what caught me was changing it to pull in more data like this:
Get-Data -Entity DataTable -Filter {idcolumn -gt 5} | ConvertTo-JSON | ConvertFrom-JSON | Add-Mdbc-Data
What I was greeted with when I ran this almost identical statement with a filter that should have grabbed several more? 1 Document. It made one freaking document and from the look of it, the array didn’t come in (because the item I looked at didn’t have one) but after a few more attempts to change my filter, I found out what was going on. I had 1 document, containing my hundreds of results for my query. So it put a level above it as if it made a database inside of the database. That could have been worked with, but boy what a pain. So what happened? Why am I getting this extra layer when it should have just grabbed the data and then put it back. Now I have to thank this post for the fix - https://stackoverflow.com/questions/20848507/why-does-powershell-give-different-result-in-one-liner-than-two-liner-when-conve After a couple hours trying to figure out conversion, I finally resolved it, this is what it ended looking like:
((Get-Data -Entity DataTable -Filter {idcolumn -gt 5} | ConvertTo-JSON) | ConvertFrom-JSON ) | Add-Mdbc-Data
So after a bit of troubleshooting, I found out that doing it that way limits what can go over the pipeline, making it only have one option instead of a chance of multiple.
0 notes
Text
[BASH][PowerShell][one-liner]被害状況等を表示する
BASH
curl -s http://l-info.rkb.jp/data.json | jq -r '.articles.article[] | [.categoryName, .detail]|@csv'| awk -F ',' '{print $1, $2}'| sed -e 's/"//g'
PowerShell
(Invoke-WebRequest -Uri http://l-info.rkb.jp/data.json | ConvertFrom-Json).articles|Foreach-Object {$_.article|Select-Object categoryName, detail}|Format-Table
0 notes
Text
How to Create a Slack Bot without using PoshBot.
If you run Windows 7 or Windows Server 2008 in your environment, PoshBot is not something you can use. This is a chat bot which connects to Slack’s API and retrieves the latest messages.
#Declare object of the Channel $MyBot = [PSCustomObject]@{ LastMessage = [decimal] 0 Channel = ‘A212’ #This needs to be set Token = 'token-1’ #This needs to be set Count = '10’ TempTimestamp = [decimal] 0 MyUserName = [string] “MyBot” MessageChannel = 'W11’ Trigger = ’@’ }
#Creates an array which contains the different channels you have. You can copy $MyBot for each channel.
$BotConfig = @() $BotConfig += $MyBot
#This is a bad name for this method, however, it gets the latest message’s timestamp.
Function GetTimeStamps ($COnfigData,$messages) { foreach ($item in $messages.messages) { if ($item.ts -gt $configdata.lastmessage) { if ($item.ts -gt $configdata.temptimestamp) { $configdata.temptimestamp = $item.ts } } } return $configdata }
Function GetMessage ($info) { $url = “https://slack.com/api/groups.history?token=” + $info.token + “&channel=” + $info.channel + “&pretty=1count=10” $data = Invoke-WebRequest $url -SessionVariable temp #Convert the data to an object $returnData = $data.Content | convertfrom-json return $returnData
} function NewActionMessage { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [PSCustomObject]$Object, [Parameter(Mandatory=$true)] [PSCustomObject]$Message )
if ($object.trigger -like $message.message.substring(0,1) -and $message.message.substring(1) -like “help*”) { SendMessage -token $Object.Token -channel $Object.MessageChannel -opt_username $Object.MyUserName -messagecontent “Welcome to help” }
}
#This loop will run forever. do { #Loop through all your channels declared earlier. foreach ($Config in $BotConfig) { #Get all messages for the channel. $apimessages = GetMessage($Config) #Store the timestamp for the newest message $c = GetTimeStamps $Config $apimessages $Config.TempTimestamp = $c.TempTimestamp #if the latest message is not set, set it to the last message, therefore nothing will happen on start-up. if ($Config.LastMessage -lt 0.01) { $Config.LastMessage = $c.TempTimestamp } #Loop through all messages foreach ($i in $apimessages.messages) { $text = $I.text $user = $i.user $ts = $i.ts #If the timestamp of the messages pulled from the Slack API are newer than the last message the Bot saw when it last ran if ($ts -gt $Config.LastMessage -and $user -notlike $Config.MyUserName -and $user -ne $null -and $user -ne “”) { #Create an object with the message, user. $TempObject = [PSCustomObject]@{ Message = $text User = $user } $r = NewActionMessage -Object $Config -Message $TempObject } } #Set the newest message from this API call to the last message received. $Config.LastMessage = $c.TempTimestamp Start-Sleep 30 }
} while ($true)
The limitations of this chat bot are that on first run it will not do anything.
@Help is the only command which works
This chat bot calls makes many calls and needs to be created as a scheduled task.
0 notes
Photo
Convertir un fichero XML en JSON desde PHP y utilizarlo desde PowerShell Fichero xml.php <?php $xml = simplexml_load_file("fich.xml"); $json = json_encode($xml); echo $json; ?> Fichero fich.xml <?xml version="1.0"?> <alumnos> <alumno id="1"> <usuario>juanito</usuario> <grupo>ventas</grupo> <programa>notepad</programa> <directorio>carpetatrabajo</directorio> <permisos>leer</permisos> </alumno> <alumno id="2"> <usuario>luis</usuario> <grupo>ventas</grupo> <programa>p7zip</programa> <directorio>carpetatrabajo</directorio> <permisos>444</permisos> </alumno> </alumnos> Analizar los datos del fichero JSON desde PowerShell $alumnos = (Invoke-WebRequest " | ConvertFrom-Json $alumnos.alumno | %{$_.'@attributes',$_.usuario}
0 notes
Video
youtube
Falcon Heavy (SpaceX Data REST API) Invoke-WebRequest " | ConvertFrom-Json Start-Process chrome (Invoke-WebRequest " | ConvertFrom-Json).links.mission_patch
#Chrome#ConvertFrom-JSON#data#Falcon Heavy#HTTPS#Invoke-WebRequest#JSON#REST API#Start-Process#Watch#Youtube
0 notes
Text
Subir un vídeo a Azure Video Indexer
#URI del servicio Azure Video Indexer $vision = 'https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns' #URL del vídeo que se va a subir $videoUrl = "https://www.jesusninoc.com/wp-content/uploads/2017/12/Introducción-a-Bash.mp4" #Petición POST con los parametros necesarios para subir el vídeo $response = Invoke-WebRequest ` -Uri ($vision +…
View On WordPress
0 notes
Text
Reconocer emociones de las caras de las personas que hay en una imagen con Emotion API de Microsoft Azure
$vision = 'https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize?' $bytes = [System.IO.File]::ReadAllBytes("C:\Users\juan\Desktop\recono\mayores.jpg") $response = Invoke-WebRequest ` -Uri "$($vision)" ` -Body $bytes ` -ContentType "application/octet-stream" ` -Headers @{'Ocp-Apim-Subscription-Key' = 'Clave del API'} ` -Method 'Post' ` -ErrorAction Stop ` -UseBasicParsing |…
View On WordPress
#Azure#ConvertFrom-JSON#Emotion API#Format-Custom#HTTPS#Invoke-WebRequest#JSON#Microsoft#Microsoft Azure#Post#UseBasicParsing
0 notes
Text
Extraer datos de varias imágenes mediante el reconocimiento óptico de caracteres y el análisis de imágenes (Computer Vision API de Microsoft Azure)
Get-ChildItem C:\Users\juan\Desktop\bodegon | %{ $vision = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze' $features = 'Categories,Tags,Description,Color' $bytes = [System.IO.File]::ReadAllBytes($_.FullName) $response = Invoke-WebRequest ` -Uri "$($vision)?visualFeatures=$($features)" ` -Body $bytes ` -ContentType "application/octet-stream" ` -Headers…
View On WordPress
#Análisis#Azure#Caracteres#Computer Vision API#ConvertFrom-JSON#Fullname#Get-ChildItem#HTTPS#Invoke-WebRequest#JSON#Microsoft#Microsoft Azure#Post#Start-Sleep#UseBasicParsing
0 notes
Text
Extraer textos de imágenes con Computer Vision API de Microsoft Azure desde PowerShell
$vision = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/ocr' $bytes = [System.IO.File]::ReadAllBytes("C:\Users\juan\Desktop\Negocios.png") $response = Invoke-WebRequest ` -Uri $vision ` -Body $bytes ` -ContentType "application/octet-stream" ` -Headers @{'Ocp-Apim-Subscription-Key' = 'Clave del API'} ` -Method 'Post' ` -ErrorAction Stop ` -UseBasicParsing | ConvertFrom-Json…
View On WordPress
#Azure#Computer Vision API#ConvertFrom-JSON#Format-Custom#HTTPS#Invoke-WebRequest#JSON#Microsoft#Post#UseBasicParsing
0 notes
Text
Extraer datos de una imagen mediante el reconocimiento óptico de caracteres y el análisis de imágenes (Computer Vision API de Microsoft Azure)
$vision = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze' $features = 'Categories,Tags,Description,Color' $bytes = [System.IO.File]::ReadAllBytes("C:\Users\juan\Desktop\recono\coche.jpg") $response = Invoke-WebRequest ` -Uri "$($vision)?visualFeatures=$($features)" ` -Body $bytes ` -ContentType "application/octet-stream" ` -Headers @{'Ocp-Apim-Subscription-Key' = 'Clave…
View On WordPress
#Análisis#Azure#Caracteres#Computer Vision API#ConvertFrom-JSON#HTTPS#Invoke-WebRequest#JSON#Microsoft#Post#UseBasicParsing
0 notes
Text
Programación Movistar+ con PowerShell
Programación Movistar+ con PowerShell
$json=(Invoke-WebRequest -Uri 'http://akamaicache.dof6.com/vod/yomvi.svc/samsung_tizen/profiles/OTT/channels?parentalRating=M18&showNonRated=true').content | ConvertFrom-JSON $json | select Nombre,@{Name="Titulo";Expression={$_.pases.titulo}} | Out-GridView
View On WordPress
0 notes
Photo
Ejercicios de PowerShell: obtener las cuentas relacionadas a otra en Twitter Start-Process chrome ' (((Invoke-WebRequest -Uri ' | ConvertFrom-JSON).related_users_html
#Chrome#ConvertFrom-JSON#Ejercicios de PowerShell#HTTPS#Invoke-WebRequest#JSON#Start-Process#Twitter
0 notes