如何从文本文件中读取每个元素
How to read each element from a TextFile
Server_Name Process_Name Server_Status Process_Available
----------- ------------ ------------- -----------------
FILESTORAGE1 notepad Online No
FILESTORAGE1 explorer Online Yes
FILESTORAGE1 Sampler Online No
FILESTORAGE1 notepad Online No
FILESTORAGE1 explorer Online Yes
FILESTORAGE1 Sampler Online Yes
FILESTORAGE1 notepad Offline No
FILESTORAGE1 explorer Offline No
FILESTORAGE1 Sampler Offline No
我的文件看起来像这样。
我想从我的文件中获取每个元素并创建一个 HTML 文件(来自此 TXT)
$bodyFromFile = Get-Content "$PSScriptRoot\data.txt"
$bodyString = $bodyFromFile | ConvertTo-Html
不幸的是,bodyString 的内容看起来是合法的 HTML。文件中的数据不在变量中。
如果您希望最终结果是表格 HTML 输出,请不要将对象转换为字符串。而不是
... | Out-String | Out-File "$PSScriptRoot\data.txt"
$bodyFromFile = Get-Content "$PSScriptRoot\data.txt"
$bodyString = $bodyFromFile | ConvertTo-Html
做这样的事情:
$table = ... | ConvertTo-Html -Fragment
$bodyString = "<body>$table</body>"
Server_Name Process_Name Server_Status Process_Available
----------- ------------ ------------- -----------------
FILESTORAGE1 notepad Online No
FILESTORAGE1 explorer Online Yes
FILESTORAGE1 Sampler Online No
FILESTORAGE1 notepad Online No
FILESTORAGE1 explorer Online Yes
FILESTORAGE1 Sampler Online Yes
FILESTORAGE1 notepad Offline No
FILESTORAGE1 explorer Offline No
FILESTORAGE1 Sampler Offline No
我的文件看起来像这样。
我想从我的文件中获取每个元素并创建一个 HTML 文件(来自此 TXT)
$bodyFromFile = Get-Content "$PSScriptRoot\data.txt"
$bodyString = $bodyFromFile | ConvertTo-Html
不幸的是,bodyString 的内容看起来是合法的 HTML。文件中的数据不在变量中。
如果您希望最终结果是表格 HTML 输出,请不要将对象转换为字符串。而不是
... | Out-String | Out-File "$PSScriptRoot\data.txt"
$bodyFromFile = Get-Content "$PSScriptRoot\data.txt"
$bodyString = $bodyFromFile | ConvertTo-Html
做这样的事情:
$table = ... | ConvertTo-Html -Fragment
$bodyString = "<body>$table</body>"