Hi, i want to construct a hash table to be used in a invoke-webrequest post as json
part of that table are phonenumbers
I have a txt file with those phonenumbers but if it try to pass them as:
[array]$numbers = gc c:\numbers.txt foreach ($number in $numbers) { $hash = @{ type = "critical" text = "TEST text alert" Date = (get-date -Format s) numbers= $number simulate= "false" } $JSON = $hash | convertto-json $url='http://myapi/ Invoke-WebRequest -uri $url -Method POST -Body $JSON -ContentType "application/json" }
It seems that if ido that i add all the properies of the file and my JSON reads like:
$JSON } { "simulate": "false", "text": "TEST text alert", "numbers": { "value": "447711111112", "PSPath": "C:\\numbers.txt", "PSParentPath": "C:\\", "PSChildName": "numbers.txt", "PSDrive": { "CurrentLocation": "", "Name": "C", "Provider": "Microsoft.PowerShell.Core\\FileSystem", "Root": "C:\\", "Description": "", "Credential": "System.Management.Automation.PSCredential", "DisplayRoot": null }, "PSProvider": { "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider", "HelpFile": "System.Management.Automation.dll-Help.xml", "Name": "FileSystem", "PSSnapIn": "Microsoft.PowerShell.Core", "ModuleName": "Microsoft.PowerShell.Core", "Module": null, "Description": "", "Capabilities": 52, "Home": "C:\\Users\\user", "Drives": "C E F" }, "ReadCount": 1 }, "type": "critical", "Date": "2015-07-27T14:52:37" } { "simulate": "false", "text": "TEST text alert", "numbers": { "value": "447722333322", "PSPath": "C:\\numbers.txt", "PSParentPath": "C:\\", "PSChildName": "numbers.txt", "PSDrive": { "CurrentLocation": "", "Name": "C", "Provider": "Microsoft.PowerShell.Core\\FileSystem", "Root": "C:\\", "Description": "", "Credential": "System.Management.Automation.PSCredential", "DisplayRoot": null }, "PSProvider": { "ImplementingType": "Microsoft.PowerShell.Commands.FileSystemProvider", "HelpFile": "System.Management.Automation.dll-Help.xml", "Name": "FileSystem", "PSSnapIn": "Microsoft.PowerShell.Core", "ModuleName": "Microsoft.PowerShell.Core", "Module": null, "Description": "", "Capabilities": 52, "Home": "C:\\Users\\users", "Drives": "C E F" }, "ReadCount": 2 }, "type": "critical", "Date": "2015-07-27T14:52:37" }
ideally i need to get just the value with the number but i can't get it to work.
Any ideas?
Thanks
- Edited by slowscripter 17 hours 58 minutes ago