MAIL SNIPPETMy JSON file export.json has this content.
[
{
"Workspace Name": "IAP IPP DW - PRD",
"Workspace Allowance": "130",
"Workspace Usage": "108.9413",
"Workspace Size Free": "21.1",
"Percentage Utilization": "0.83801",
"Predicted Usage": "146.9888958"
},
{
"Workspace Name": "Connected planning Facilities-PRD",
"Workspace Allowance": "130",
"Workspace Usage": "81.2462",
"Workspace Size Free": "48.8",
"Percentage Utilization": "0.624970769",
"Predicted Usage": "85.79967522"
},
{
"Workspace Name": "Lubes SDA - PROD",
"Workspace Allowance": "100",
"Workspace Usage": "78.5773",
"Workspace Size Free": "21.4",
"Percentage Utilization": "0.785773",
"Predicted Usage": "87.03502547"
},
{
"Workspace Name": "IAP IPP DW - ACC",
"Workspace Allowance": "100",
"Workspace Usage": "56.272",
"Workspace Size Free": "43.7",
"Percentage Utilization": "0.56272",
"Predicted Usage": "95.58173647"
},
{
"Workspace Name": "ONE Forecast UPD - PRD",
"Workspace Allowance": "100",
"Workspace Usage": "42.1855",
"Workspace Size Free": "57.8",
"Percentage Utilization": "0.421855",
"Predicted Usage": "51.76880067"
},
{
"Workspace Name": "IAP IPP DW - DEV",
"Workspace Allowance": "50",
"Workspace Usage": "38.7354",
"Workspace Size Free": "11.3",
"Percentage Utilization": "0.774708",
"Predicted Usage": "33.98943696"
}
]
When I write the below code in POWER SHELL it displays the data set for "Connected planning Facilities-PRD" and "Lubes SDA - PROD" but does not display for "IAP IPP DW - PRD" which should ideally show up because the Workspace Usage for that Model is also 108.
$variable =Get-Content "export.json" | ConvertFrom-Json
#Write-Output $variable
$logs=$variable | Where-Object { $_.'Workspace Usage' -ge "75" }
Write-Output $logs
PLEASE HELP
function HtmlTable
{
[OutputType([System.Object])]
Param (
[Parameter(Mandatory=$True)]
[String[]]
$tableRows,
[Parameter(Mandatory=$True)]
[String[]]
$tableHeaders,
[Parameter(Mandatory=$True)]
$tableWidthPercentage
)
$htmTable = "<html>
<style>
body {font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;}
table{width: $tableWidthPercentage;border-collapse: collapse;}
th{background-color:#106ebe; color:white;font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;border: 1px solid black;padding: 4px;text-align: left;border: 1px solid #ddd;}
tr:nth-child(even){background-color: #f2f2f2;}
td{font-family:Segoe UI, Helvetica Neue, Helvetica, Arial, Verdana;font-size:12px;border: 1px solid #ddd;padding: 4px;}
</style>
<table>
<tr>"
Foreach ($header in $tableHeaders)
{
$htmTable += "<th>$header</th>"
}
$htmTable +="</tr>
$tableRows
</table>"
return $htmTable
}
$variable =Get-Content -raw "export.json" | ConvertFrom-Json
#$logs=$variable | Where-Object { $_.'Workspace Name' -eq "IAP IPP DW - PRD" -and $_.'Workspace Usage' -gt 75}
$logs=$variable | Where-Object { $_.'Workspace Usage' -gt 75 }
foreach($item in $logs)
{
$WorkspaceName =$item.'Workspace Name'
$WorkspaceAllowance=$item.'Workspace Allowance'
$WorkspaceUsage=$item.'Workspace Usage '
$WorkspaceSizeFree=$item.'Workspace Size Free'
$PercentageUtilization=$item.'Percentage Utilization'
$PredictedUsage=$item.'Predicted Usage'
$resultRow = "
<tr>
<td>$WorkspaceName</td>
<td>$WorkspaceAllowance</td>
<td>$WorkspaceUsage</td>
<td>$WorkspaceSizeFree</td>
<td>$PercentageUtilization</td>
<td>$PredictedUsage</td>
</tr>
"
$table_content += $resultRow
}
$body = HtmlTable -tableWidthPercentage 90% -tableRows $table_content -tableHeaders WorkspaceName,WorkspaceAllowance,WorkspaceUsage,WorkspaceSizeFree,PercentageUtilization,PredictedUsage
Send-MailMessage -From <from address> -To <to address> -Cc <cclist> -SmtpServer <smtp server address> -Subject "testing script" -Body $body -BodyAsHtml
Clear-Variable -Name "logs"
Write-Host "Done Sending Email"
<#
Please update the below details from the PowerShell script
Send-MailMessage -From <from address> -To <to address> -Cc <cclist> -SmtpServer <smtp server address> -Subject "testing script" -Body $body -BodyAsHtml
#>
***PFA for sample output. Also please mark this as answer if you feel this is an answer***
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments