powershell - Powershell 不会在电子邮件 html 正文中输出“£”
问题描述
我有以下代码,它计算特定文件夹中的 PDF 数量,计算这些特定 PDF 中的工作表数量,并发送包含此数据的电子邮件。
我已经匿名了部分脚本。
Set-ExecutionPolicy Unrestricted
#This gets the number of PDF files in the Archive folder, this shows the successful uploads to Portal.
$Archive = $($compareDate = (Get-Date).AddDays(-7)
@(Get-ChildItem -Path "C:\Archive\*.*" -Filter *.pdf -Recurse | Where-Object { $_.LastWriteTime -gt $compareDate}).Count)
#This gets the number of PDF files in the Exception folder, this shows the failed uploads to Portal.
$Exception = $($compareDate = (Get-Date).AddDays(-7)
@(Get-ChildItem -Path "C:\Exception\*.*" -Filter *.pdf -Recurse | Where-Object { $_.LastWriteTime -gt $compareDate}).Count)
#This gets the number of pages in all PDF files succsssfully upoaded to Portal.
$folder = $($compareDate = (Get-Date).AddDays(-7)
@(Get-ChildItem -Path "C:\Archive\*.*" -Filter *.pdf -Recurse | Where-Object { $_.LastWriteTime -gt $compareDate}))
$Count = $Files = 0
foreach($File in (Get-ChildItem -Path $Folder -Filter *.pdf)){
$Pages = (C:\PS_Scripts\xpdf-tools-win-4.02\xpdf-tools-win-4.02\bin64\pdfinfo.exe $File.FullName | Select-String -Pattern '(?<=Pages:\s*)\d+').Matches.Value
$Count += $Pages
$Files++}
$Count
#This calculates the saving on sheets of paper, not including ink and printers. Each ream of 500 sheets costs us £1.98. So a single sheet costs 0.4 pence
$Saving = (($Count*0.4)/100)
#This converts the number to £nn.nn
$Pounds = '{0:C}' -f $Saving
$Pounds
#This gets Mondays Date
$Friday= (Get-Date).AddDays(-7).ToString('dd/MM/yyyy')
#This gets Sundays Date
$Thursday= (Get-Date).AddDays(-1).ToString('dd/MM/yyyy')
#This begins the email
$recipients = "user1 <user1@email.com>"
send-mailmessage -from "emailtest@email.com" `
-to $recipients `
-Subject "Weekly Data" `
-body "Hi all,
<br />
<br />
Please find below the weekly stats for Reports going to Portal.
<br />
<br />
From Friday to Thursday ($Friday- $Thursday), there were $Archive successful automated reports sent to Portal.
<br />
<br />
This saved us printing, and scanning $Count pages of paper.
<br />
<br />
This amounts to roughly $Pounds in savings during this period on paper alone!
<br />
<br />
Also, during this same period, there were $Exception failed reports sent to Portal, these have either been rectified or will be rectified imminently.
<br />
<br />
<br />"`
-BodyAsHtml `
-priority Normal `
-dno onSuccess, onFailure `
-smtpServer egat@email.com
Set-ExecutionPolicy Restricted
我的问题专门针对 $Pounds,它可以完成我想要做的所有事情。它以以下格式输出计算,£nn.nn,例如:£45.52 我已经确认了这一点,因为在 Powershell ISE 中我返回 $Pounds 的值以检查它是否有效。
但是当我收到电子邮件时,£ 符号被替换为“?”,请参阅下面的电子邮件副本,
大家好,
请在下面找到传送到 Portal 的报告的每周统计数据。
从上周的周一到周日(01/05/2020 - 07/05/2020),共有 235 份成功的自动报告发送到 Portal。
这为我们节省了打印和扫描 1256 页纸的时间。
仅在此期间,仅在纸面上就节省了大约 5.02 欧元!
此外,在同一时期,向 Portal 发送了 0 次失败的报告,这些报告要么已经纠正,要么即将纠正。
为什么不显示 5.02 英镑?
任何帮助将不胜感激。
谢谢, 乌胡杰
解决方案
您可以使用以下HttpUtility类“Html Entify”磅符号System.Web
:
Add-Type -AssemblyName System.Web
$Pound = [System.Web.HttpUtility]::HtmlEncode('£123.456')
输出
£123.456
在 HTML 中显示
£123.456
推荐阅读
- python - 为什么 pd.read_csv 不接受 Windows 文件路径中的变量名?
- c++ - 文件系统 value_type 指向字符串的指针?
- javascript - 错误:passport.initialize() 中间件未使用(代码顺序正确)
- javascript - 如何访问类组件中的上下文以进行本机反应?
- c# - WPF:VS 预览与实际应用程序不匹配
- javascript - 我应该使用什么功能来使用左右箭头键更改图像
- python - Pytorch Lightning Transformer:“AttributeError:‘MyTextClassificationTransformer’对象没有属性‘num_classes’”
- sorting - 有没有办法对一组数字进行自定义排序,以便它们在山上排序?
- c# - 如何强制 setValue 到 Registry64
- c# - 使用 Identityserver4 进行自定义身份验证,通过 OTP 手机号码或仅用户名获取令牌