[英]List inside an HTML Tag -PowerShell
I have a PoweShell command that lists all files from my path.我有一个 PoweShell 命令,它列出了我路径中的所有文件。
I need to list when I do HTML tag to send an e-mail.当我使用 HTML 标签发送电子邮件时,我需要列出。
Here is my code,这是我的代码,
# To List File
$listFiles = Get-ChildItem -path $mypath
In my Email Message Body:在我的 Email 消息正文中:
$emailMessage.Body = @"
<h4>Folder Path: </h4><p>$mypath</p>
<h3> List of files: </h3>
<li>$listFiles</li>
"@
I get this,我明白了,
Folder Path:
C:my_tes\test_file_path
List of files:
• Test_Document_1.txt Test_Document_2.txt WorkBook_Test_1.xlsx
But I need this,但我需要这个,
Folder Path:
C:my_tes\test_file_path
List of files:
• Test_Document_1.txt
• Test_Document_2.txt
• WorkBook_Test_1.xlsx
I tried the following(did not get what I want),我尝试了以下(没有得到我想要的),
$emailMessage.Body = @"
<h4>Folder Path: </h4><p>$mypath</p>
<h3> List of files: </h3>
Foreach(<li>$i</li> in $listFiles)
How can I modify my <li>
html tag to get the desired output?如何修改我的
<li>
html 标签以获得所需的 output?
Try this above your existing code:在现有代码上方尝试此操作:
$listFiles = Foreach($item in $listFiles) {
"<li>$item</li>"
}
Then using $listItems
in your email body where the loop is.然后在循环所在的 email 主体中使用
$listItems
。
To output an Unordered list, you also need to enclose the <li>..</li>
elements inside <ul>..</ul>
tags.要 output 是一个无序列表,您还需要将
<li>..</li>
元素包含在<ul>..</ul>
标记内。
The eastiest thing to do is to build the list of file tags straight from the Get-ChildItem
cmdlet:最简单的做法是直接从
Get-ChildItem
cmdlet 构建文件标签列表:
$listFiles = Get-ChildItem -Path $mypath -File | ForEach-Object { '<li>{0}</li>' -f $_.Name }
$emailMessage.Body = @"
<h4>Folder Path: </h4><p>$mypath</p>
<h3> List of files: </h3>
<ul>$listFiles</ul>
"@
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.