I have developed a powershell script which generates a JSON file which am trying to parse using JQuery.
var mydata = jQuery.parseJSON(w3wp);
w3wp = '[{"Pid" : "6724" , "Apppool" : "myapppool1" , "Usage" : "229.328125"},{"Pid" : "6808" , "Apppool" : "myapppool2" , "Usage" : "152" }]';
There are no issues found when the JSON data is in a single line like above, the script works fine. If the json data is formatted like below i am getting "undefined error in w3wp."
w3wp = '[{"Pid" : "6724" , "Apppool" : "myapppool1" , "Usage" : "229.328125"},
{"Pid" : "6808" , "Apppool" : "myapppool2" , "Usage" : "152" }]';
The representation above is with very minimal data in real time scenario the number of app pools are huge and power-shell word wraps in 2.0 and am having issues with the JSON file. Is there any way to format this Json file so i can use this for parsing ?
Based on request here is the powershell script
$host.UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size 5512,100
function get-apppool {
[regex]$pattern="-ap ""(.+)"""
$contentx="w3wp = '["
gwmi win32_process -filter 'name="w3wp.exe"' | % {
$name=$_.name
$cmd = $pattern.Match($_.commandline).Groups[1].Value
$procid = $_.ProcessId
$cpuper = get-process | where-object {$_.id -like $procid} | select -Expand CPU
$contentx = $contentx + "{""Pid"" : ""$procid"" , ""Apppool"" : ""$cmd"" , ""Usage"" : ""$cpuper"" }"
$contentx = $contentx + ","
}
$contentx = $contentx -replace ".$"
$contentx = $contentx + "]';"
write-host -nonewline $contentx > dsdf.json
}
get-apppool