我坚持一个简单的任务,在几次更新(Update-Help
)之后用CSS将任何进程列表转换为HTML文件,我最终使用命令(Invoke-Expression .\test.html
)成功输出HTML,但是没有添加CSS样式,从技术上讲,文件 test.css 不存在。
你能否澄清可能出错的地方,我只是使用YouTube中的简短例子,整个过程非常精细。
我的代码:
gsv | Select Name, Status | ConvertTo-Html -CSSUri c:\test.css | Out-File test.html
Invoke-Expression .\test.html
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
<link rel="stylesheet" type="text/css" href="file:///c:/test.css" />
</head><body>
<table>
<colgroup><col/><col/></colgroup>
<tr><th>Name</th><th>Status</th></tr>
<tr><td>ABBYY.Licensing.Lingvo.Desktop.14.0</td><td>Running</td></tr>
<tr><td>AdobeARMservice</td><td>Running</td></tr>
<tr><td>AGSService</td><td>Running</td></tr>
<tr><td>AJRouter</td><td>Stopped</td></tr>
<tr><td>ALG</td><td>Stopped</td></tr>
<tr><td>AppIDSvc</td><td>Stopped</td></tr>
<tr><td>Appinfo</td><td>Running</td></tr>
<tr><td>AppMgmt</td><td>Stopped</td></tr>
<tr><td>AppReadiness</td><td>Stopped</td></tr>
<tr><td>AppXSvc</td><td>Stopped</td></tr>
<tr><td>Archos Sepang Modem Device Helper</td><td>Running</td></tr>
<tr><td>ASGT</td><td>Running</td></tr>
<tr><td>aspnet_state</td><td>Stopped</td></tr>
<tr><td>AudioEndpointBuilder</td><td>Running</td></tr>
<tr><td>Audiosrv</td><td>Running</td></tr>
<tr><td>AxInstSV</td><td>Stopped</td></tr>
<tr><td>BDESVC</td><td>Stopped</td></tr>
<tr><td>BFE</td><td>Running</td></tr>
<tr><td>BITS</td><td>Running</td></tr>
<tr><td>BrokerInfrastructure</td><td>Running</td></tr>
<tr><td>Browser</td><td>Stopped</td></tr>
<tr><td>BthHFSrv</td><td>Stopped</td></tr>
<tr><td>bthserv</td><td>Stopped</td></tr>
<tr><td>CDPSvc</td><td>Stopped</td></tr>
<tr><td>CertPropSvc</td><td>Running</td></tr>
<tr><td>ClipSVC</td><td>Stopped</td></tr>
<tr><td>COMSysApp</td><td>Stopped</td></tr>
<tr><td>CoreMessagingRegistrar</td><td>Running</td></tr>
<tr><td>CryptSvc</td><td>Running</td></tr>
<tr><td>CscService</td><td>Stopped</td></tr>
<tr><td>DcomLaunch</td><td>Running</td></tr>
<tr><td>DcpSvc</td><td>Stopped</td></tr>
<tr><td>defragsvc</td><td>Stopped</td></tr>
<tr><td>DeviceAssociationService</td><td>Stopped</td></tr>
<tr><td>DeviceInstall</td><td>Stopped</td></tr>
<tr><td>DevQueryBroker</td><td>Stopped</td></tr>
<tr><td>Dhcp</td><td>Running</td></tr>
<tr><td>diagnosticshub.standardcollector.service</td><td>Stopped</td></tr>
<tr><td>DiagTrack</td><td>Running</td></tr>
<tr><td>Disc Soft Ultra Bus Service</td><td>Stopped</td></tr>
<tr><td>DmEnrollmentSvc</td><td>Stopped</td></tr>
<tr><td>dmwappushservice</td><td>Stopped</td></tr>
<tr><td>Dnscache</td><td>Running</td></tr>
<tr><td>DoSvc</td><td>Running</td></tr>
<tr><td>dot3svc</td><td>Stopped</td></tr>
<tr><td>DPS</td><td>Running</td></tr>
<tr><td>DsmSvc</td><td>Stopped</td></tr>
<tr><td>DsSvc</td><td>Stopped</td></tr>
<tr><td>Eaphost</td><td>Stopped</td></tr>
<tr><td>EFS</td><td>Stopped</td></tr>
<tr><td>embeddedmode</td><td>Stopped</td></tr>
<tr><td>EntAppSvc</td><td>Stopped</td></tr>
<tr><td>EventLog</td><td>Running</td></tr>
<tr><td>EventSystem</td><td>Running</td></tr>
<tr><td>Fax</td><td>Stopped</td></tr>
<tr><td>fdPHost</td><td>Stopped</td></tr>
<tr><td>FDResPub</td><td>Stopped</td></tr>
<tr><td>fhsvc</td><td>Stopped</td></tr>
<tr><td>FontCache</td><td>Running</td></tr>
<tr><td>FontCache3.0.0.0</td><td>Running</td></tr>
<tr><td>fussvc</td><td>Stopped</td></tr>
<tr><td>GfExperienceService</td><td>Running</td></tr>
<tr><td>gpsvc</td><td>Running</td></tr>
<tr><td>gupdate</td><td>Stopped</td></tr>
<tr><td>gupdatem</td><td>Stopped</td></tr>
<tr><td>hidserv</td><td>Running</td></tr>
<tr><td>HomeGroupProvider</td><td>Stopped</td></tr>
<tr><td>icssvc</td><td>Stopped</td></tr>
<tr><td>IEEtwCollectorService</td><td>Stopped</td></tr>
<tr><td>IKEEXT</td><td>Stopped</td></tr>
<tr><td>iphlpsvc</td><td>Running</td></tr>
<tr><td>KeyIso</td><td>Running</td></tr>
<tr><td>KtmRm</td><td>Stopped</td></tr>
<tr><td>LanmanServer</td><td>Running</td></tr>
<tr><td>LanmanWorkstation</td><td>Running</td></tr>
<tr><td>lfsvc</td><td>Running</td></tr>
<tr><td>LicenseManager</td><td>Stopped</td></tr>
<tr><td>lltdsvc</td><td>Stopped</td></tr>
<tr><td>lmhosts</td><td>Running</td></tr>
<tr><td>LSM</td><td>Running</td></tr>
<tr><td>MapsBroker</td><td>Stopped</td></tr>
<tr><td>MpsSvc</td><td>Running</td></tr>
<tr><td>MSDTC</td><td>Stopped</td></tr>
<tr><td>MSiSCSI</td><td>Stopped</td></tr>
<tr><td>msiserver</td><td>Stopped</td></tr>
<tr><td>NcaSvc</td><td>Stopped</td></tr>
<tr><td>NcbService</td><td>Running</td></tr>
<tr><td>NcdAutoSetup</td><td>Stopped</td></tr>
<tr><td>Netlogon</td><td>Stopped</td></tr>
<tr><td>Netman</td><td>Running</td></tr>
<tr><td>netprofm</td><td>Running</td></tr>
<tr><td>NetSetupSvc</td><td>Stopped</td></tr>
<tr><td>NetTcpPortSharing</td><td>Stopped</td></tr>
<tr><td>NgcCtnrSvc</td><td>Stopped</td></tr>
<tr><td>NgcSvc</td><td>Stopped</td></tr>
<tr><td>NlaSvc</td><td>Running</td></tr>
<tr><td>nsi</td><td>Running</td></tr>
<tr><td>NvNetworkService</td><td>Running</td></tr>
<tr><td>NvStreamSvc</td><td>Running</td></tr>
<tr><td>nvsvc</td><td>Running</td></tr>
<tr><td>p2pimsvc</td><td>Stopped</td></tr>
<tr><td>p2psvc</td><td>Stopped</td></tr>
<tr><td>PcaSvc</td><td>Running</td></tr>
<tr><td>PeerDistSvc</td><td>Stopped</td></tr>
<tr><td>PerfHost</td><td>Stopped</td></tr>
<tr><td>PhoneSvc</td><td>Stopped</td></tr>
<tr><td>pla</td><td>Stopped</td></tr>
<tr><td>PlugPlay</td><td>Running</td></tr>
<tr><td>PNRPAutoReg</td><td>Stopped</td></tr>
<tr><td>PNRPsvc</td><td>Stopped</td></tr>
<tr><td>PolicyAgent</td><td>Running</td></tr>
<tr><td>Power</td><td>Running</td></tr>
<tr><td>PrintNotify</td><td>Stopped</td></tr>
<tr><td>ProfSvc</td><td>Running</td></tr>
<tr><td>QWAVE</td><td>Running</td></tr>
<tr><td>RasAuto</td><td>Stopped</td></tr>
<tr><td>RasMan</td><td>Running</td></tr>
<tr><td>RemoteAccess</td><td>Stopped</td></tr>
<tr><td>RemoteRegistry</td><td>Stopped</td></tr>
<tr><td>RetailDemo</td><td>Stopped</td></tr>
<tr><td>RpcEptMapper</td><td>Running</td></tr>
<tr><td>RpcLocator</td><td>Stopped</td></tr>
<tr><td>RpcSs</td><td>Running</td></tr>
<tr><td>SamSs</td><td>Running</td></tr>
<tr><td>SCardSvr</td><td>Stopped</td></tr>
<tr><td>ScDeviceEnum</td><td>Stopped</td></tr>
<tr><td>Schedule</td><td>Running</td></tr>
<tr><td>SCPolicySvc</td><td>Stopped</td></tr>
<tr><td>SDRSVC</td><td>Stopped</td></tr>
<tr><td>seclogon</td><td>Running</td></tr>
<tr><td>SENS</td><td>Running</td></tr>
<tr><td>SensorDataService</td><td>Stopped</td></tr>
<tr><td>SensorService</td><td>Stopped</td></tr>
<tr><td>SensrSvc</td><td>Stopped</td></tr>
<tr><td>Service KMSELDI</td><td>Running</td></tr>
<tr><td>SessionEnv</td><td>Running</td></tr>
<tr><td>SharedAccess</td><td>Stopped</td></tr>
<tr><td>ShellHWDetection</td><td>Running</td></tr>
<tr><td>smphost</td><td>Running</td></tr>
<tr><td>SmsRouter</td><td>Stopped</td></tr>
<tr><td>SNMPTRAP</td><td>Stopped</td></tr>
<tr><td>Spooler</td><td>Running</td></tr>
<tr><td>sppsvc</td><td>Stopped</td></tr>
<tr><td>SQLWriter</td><td>Running</td></tr>
<tr><td>SSDPSRV</td><td>Running</td></tr>
<tr><td>SstpSvc</td><td>Running</td></tr>
<tr><td>StateRepository</td><td>Running</td></tr>
<tr><td>Stereo Service</td><td>Running</td></tr>
<tr><td>stisvc</td><td>Stopped</td></tr>
<tr><td>StorSvc</td><td>Running</td></tr>
<tr><td>svsvc</td><td>Stopped</td></tr>
<tr><td>swprv</td><td>Stopped</td></tr>
<tr><td>SysMain</td><td>Running</td></tr>
<tr><td>SystemEventsBroker</td><td>Running</td></tr>
<tr><td>TabletInputService</td><td>Stopped</td></tr>
<tr><td>TapiSrv</td><td>Running</td></tr>
<tr><td>Te.Service</td><td>Stopped</td></tr>
<tr><td>TermService</td><td>Running</td></tr>
<tr><td>Themes</td><td>Running</td></tr>
<tr><td>TieringEngineService</td><td>Stopped</td></tr>
<tr><td>tiledatamodelsvc</td><td>Running</td></tr>
<tr><td>TimeBroker</td><td>Running</td></tr>
<tr><td>TrkWks</td><td>Running</td></tr>
<tr><td>TrustedInstaller</td><td>Stopped</td></tr>
<tr><td>tzautoupdate</td><td>Stopped</td></tr>
<tr><td>UI0Detect</td><td>Stopped</td></tr>
<tr><td>UmRdpService</td><td>Running</td></tr>
<tr><td>upnphost</td><td>Stopped</td></tr>
<tr><td>UserManager</td><td>Running</td></tr>
<tr><td>UsoSvc</td><td>Stopped</td></tr>
<tr><td>VaultSvc</td><td>Running</td></tr>
<tr><td>vds</td><td>Stopped</td></tr>
<tr><td>vmicguestinterface</td><td>Stopped</td></tr>
<tr><td>vmicheartbeat</td><td>Stopped</td></tr>
<tr><td>vmickvpexchange</td><td>Stopped</td></tr>
<tr><td>vmicrdv</td><td>Stopped</td></tr>
<tr><td>vmicshutdown</td><td>Stopped</td></tr>
<tr><td>vmictimesync</td><td>Stopped</td></tr>
<tr><td>vmicvmsession</td><td>Stopped</td></tr>
<tr><td>vmicvss</td><td>Stopped</td></tr>
<tr><td>VSS</td><td>Stopped</td></tr>
<tr><td>VSStandardCollectorService140</td><td>Stopped</td></tr>
<tr><td>W32Time</td><td>Running</td></tr>
<tr><td>WalletService</td><td>Stopped</td></tr>
<tr><td>wbengine</td><td>Stopped</td></tr>
<tr><td>WbioSrvc</td><td>Stopped</td></tr>
<tr><td>Wcmsvc</td><td>Running</td></tr>
<tr><td>wcncsvc</td><td>Stopped</td></tr>
<tr><td>WcsPlugInService</td><td>Stopped</td></tr>
<tr><td>WdiServiceHost</td><td>Running</td></tr>
<tr><td>WdiSystemHost</td><td>Stopped</td></tr>
<tr><td>WdNisSvc</td><td>Running</td></tr>
<tr><td>WebClient</td><td>Stopped</td></tr>
<tr><td>Wecsvc</td><td>Stopped</td></tr>
<tr><td>WEPHOSTSVC</td><td>Stopped</td></tr>
<tr><td>wercplsupport</td><td>Stopped</td></tr>
<tr><td>WerSvc</td><td>Stopped</td></tr>
<tr><td>WiaRpc</td><td>Stopped</td></tr>
<tr><td>WinDefend</td><td>Running</td></tr>
<tr><td>WinHttpAutoProxySvc</td><td>Running</td></tr>
<tr><td>Winmgmt</td><td>Running</td></tr>
<tr><td>WinRM</td><td>Stopped</td></tr>
<tr><td>WlanSvc</td><td>Stopped</td></tr>
<tr><td>wlidsvc</td><td>Stopped</td></tr>
<tr><td>wmiApSrv</td><td>Stopped</td></tr>
<tr><td>WMPNetworkSvc</td><td>Stopped</td></tr>
<tr><td>workfolderssvc</td><td>Stopped</td></tr>
<tr><td>WPDBusEnum</td><td>Stopped</td></tr>
<tr><td>WpnService</td><td>Stopped</td></tr>
<tr><td>wscsvc</td><td>Running</td></tr>
<tr><td>WSearch</td><td>Running</td></tr>
<tr><td>WSService</td><td>Stopped</td></tr>
<tr><td>wuauserv</td><td>Running</td></tr>
<tr><td>wudfsvc</td><td>Running</td></tr>
<tr><td>WwanSvc</td><td>Stopped</td></tr>
<tr><td>XblAuthManager</td><td>Stopped</td></tr>
<tr><td>XblGameSave</td><td>Stopped</td></tr>
<tr><td>XboxNetApiSvc</td><td>Stopped</td></tr>
</table>
</body></html>
答案 0 :(得分:0)
我会注意到执行此操作时,文件c:\ test.css不会嵌入到html文件中。因此,如果你使用它来制作一个html文件并移动它,那么css文件必须随之移动。典型的www目录如下所示:
\css\styles.css
index.html
并且html文件的头部看起来像这样:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
...
因此在这种情况下,style.css文件不是静态路径。
答案 1 :(得分:0)
另一个选择是在GitHub上使用这个ConvertToHtml模块。
我没有尝试自我推广,但我写了这个,因为内置的PowerShell cmdlet对表格的格式化功能有限,听起来这可能更接近你想要的。
我主要使用它来发送Outlook中的报告,上次我测试Outlook 2013似乎只适用于内联样式。所以,该模块目前使用内联样式,但如果你制作PR或文件是一个问题(我碰巧得到空闲时间),这听起来像一个有用的功能。
CI系统具有非常简单的示例工件,用于验证构建是否良好。 Examples.zip
文档目前相当稀少。有一个关于输出外观的JSON描述。如果您对使用该模块感兴趣,我可以更新自述文件,在GitHub上提出问题。
答案 2 :(得分:0)
如果CSS文件不存在,则需要先创建它,然后才能在HTML文件中使用它:
@'
table {
border: 1px solid #000000;
border-collapse: collapse;
}
td {
font-family: arial, helvetica, sans-serif;
}
'@ | Set-Content 'test.css'
... | ConvertTo-Html -CSSUri 'test.css' | Out-File 'test.html'
更好的是,如果您想要动态创建所有内容,请不要费心将样式表写入文件。而是将样式作为标题插入到生成的HTML中:
$style = @'
<style type="text/css">
table {
border: 1px solid #000000;
border-collapse: collapse;
}
td {
font-family: arial, helvetica, sans-serif;
}
</style>
'@
... | ConvertTo-Html -Head $style | Out-File 'test.html'
答案 3 :(得分:0)
但有时您希望将样式表放在单独的 CSS 文件中。这更容易编辑或替换。然后您可以简单地读取脚本中的 CSS 文件并将其存储在 $header 变量中。然后可以在 ConvertTo-Html 命令中进行处理。这是一个例子。
CSS 文件:
/* MyCssFile.css */
table {
border: 1px solid #000000;
border-collapse: collapse;
}
td {
font-family: arial, helvetica, sans-serif;
}
PowerShell 脚本:
...
$Css = Get-Content -Path '.\MyCssFile.css' -Raw
$style= ("<style>`n") + $Css + ("`n</style>")
...
... | ConvertTo-Html -Head $style | Out-File -Path 'test.html'
这里的优点是,您将所有 html 代码放在一个文件中。例如,这对于通过电子邮件发送的报告很方便。