我制作了这个脚本,以便在计算机上保存服务的HTML文件,并添加附件。
$a = "<style>"
$a = $a + "BODY{background-color:peachpuff;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$a = $a + "strong{color: green;}"
$a = $a + "</style>"
$b = "<H2>Service Information</H2>"
$b = $b + "<p> This is the list of services that are on this system. It dispays <strong>both</strong> running and stopped services </p>"
Get-Service | Select-Object Status, Name, DisplayName |
ConvertTo-HTML -head $a -body $b |
Out-File C:\Scripts\Test.htm
start "C:\Users\neela\Desktop\Services In HTML.ps1"
Invoke-Expression C:\Scripts\Test.htm
但是,我不喜欢这种字体。我想使用谷歌的Ubuntu字体。我尝试添加一些代码来完成这项工作:
$a = $a + "@import url('https://fonts.googleapis.com/css?family=Ubuntu');"
$a = $a + "font-family: 'Ubuntu', sans-serif;"
然而,它不起作用。现在我怎么改变这个?
要将所选字体嵌入网页,请将此代码复制到HTML文档中。
<style>
@import url('https://fonts.googleapis.com/css?family=Ubuntu');
</style>
使用以下CSS规则指定这些系列:
font-family: 'Ubuntu', sans-serif;
答案 0 :(得分:1)
在现有样式上方添加样式导入,然后将css规则应用于您希望的任何元素。在这种情况下,我将它应用于身体。我还建议在这里使用字符串而不是+ =,因为它们更具可读性。
$a = @"
<style>
@import url('https://fonts.googleapis.com/css?family=Ubuntu')
</style>
<style>
BODY{background-color:peachpuff; font-family: 'Ubuntu', sans-serif;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}
TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}
strong{color: green;}
</style>
"@
$b = @"
<H2>Service Information</H2>
<p> This is the list of services that are on this system. It dispays <strong>both</strong> running and stopped services </p>
"@
Get-Service | Select-Object Status, Name, DisplayName |
ConvertTo-HTML -Head $a -Body $b |
Out-File C:\Scripts\Test.htm
Invoke-Item C:\Scripts\Test.htm