英文:
How to use Variables in JSON in PS script
问题
Email i recieve as result :
Dobry den,
Dnes od $TaskTime probehne release do Vyvojoveho prostredi. Nasazeny budou upravy : $ReleasedFeatures
Result i expect/want :
Dobry den,
Dnes od 16:52 probehne release do Vyvojoveho prostredi. Nasazeny budou upravy :
CDR7494 BC storno polozek DM a doplneni kodu partnera transakce
CDR7314 BC automaticke generovani nakupnich faktur ze smluv
CDR7509 nelze tisknout prodejni faktury ktere nemaji vyplnene centrum odpovednosti chyba v priloze CDR7514 BC MO Vychozi hodnota prijmout u moznosti uctovani nakupnich objednavek
CDR7215 BC objednavky BC doplneni zustatku
CDR7444 BC Prodejni faktury generovane ze smluv popise
英文:
i wanted to create script to send email with list of new features ( releaselist) using PS script with setting json to Declare recipiants list etc. But how can i use Variables in this json file?
PS script i´m using
#emailsendscript
$SettingsObject = Get-Content -Path C:\Temp\Settings.JSON | ConvertFrom-Json
$EmailFrom = $SettingsObject.'$EmailFrom'
$EmailTo = $SettingsObject.'$EmailTo'
$Subject = $SettingsObject.'$Subject'
$Body = $SettingsObject.'$Body'
$SMTPServer = “smtp.office365.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($EmailFrom, “*****”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
json file i´m using :
{
"$TaskName": "Release Verze 34",
"$TaskTime": "16:52",
"$ReleasedFeatures": "CDR7494 BC storno polozek DM a doplneni kodu partnera transakce \n CDR7314 BC automaticke generovani nakupnich faktur ze smluv \n CDR7509 nelze tisknout prodejni faktury ktere nemaji vyplnene centrum odpovednosti chyba v priloze \n CDR7514 BC MO Vychozi hodnota prijmout u moznosti uctovani nakupnich objednavek \n CDR7215 BC objednavky BC doplneni zustatku \n CDR7444 BC Prodejni faktury generovane ze smluv popise",
"$EmailFrom": "***@*.*",
"$EmailTo": "***@*.*",
"$Subject": "Release do vyvojoveho prostredi",
"$SubjectFinish": "Release do vyvojoveho prostredi - hotovo",
"$Body": "Dobry den, \n Dnes od $TaskTime probehne release do Vyvojoveho prostredi. Nasazeny budou upravy : $ReleasedFeatures",
"$BodyFinish": "Dobry den, \n Release verze **$AppVersionNo** probehl uspesne. \n Jakub Soucek",
"$DeploymentInstance": "SSC175"
}
Email i recieve as result :
Dobry den,
Dnes od $TaskTime probehne release do Vyvojoveho prostredi. Nasazeny budou upravy : $ReleasedFeatures
Result i expect/want :
Dobry den,
Dnes od 16:52 probehne release do Vyvojoveho prostredi. Nasazeny budou upravy :
CDR7494 BC storno polozek DM a doplneni kodu partnera transakce
CDR7314 BC automaticke generovani nakupnich faktur ze smluv
CDR7509 nelze tisknout prodejni faktury ktere nemaji vyplnene centrum odpovednosti chyba v priloze CDR7514 BC MO Vychozi hodnota prijmout u moznosti uctovani nakupnich objednavek
CDR7215 BC objednavky BC doplneni zustatku
CDR7444 BC Prodejni faktury generovane ze smluv popise`
答案1
得分: 1
...
$TaskTime=$SettingsObject.'$TaskTime'
$ReleasedFeatures=$SettingsObject.'$ReleasedFeatures'
$Body=$SettingsObject.'$Body'
$Body=$Body.replace('$TaskTime',$TaskTime)
$Body=$Body.replace('$ReleasedFeatures',$ReleasedFeatures)
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
英文:
You would have to replace the literal variables with the actual values, so:
...
$TaskTime=$SettingsObject.'$TaskTime'
$ReleasedFeatures=$SettingsObject.'$ReleasedFeatures'
$Body=$SettingsObject.'$Body'
$Body=$Body.replace('$TaskTime',$TaskTime)
$Body=$Body.replace('$ReleasedFeatures',$ReleasedFeatures)
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论