输出到HTML问题

时间:2017-07-14 15:40:06

标签: powershell

你好PS,我有一个问题,输出输出数据。

HTM文件已创建,但没有数据,我在这里缺少什么,再次我是新的!

这是检查TSM备份报告并在关闭时启动服务。

这是脚本

$serverlist  = gc servers.txt
$SvcName = '*tsm*scheduler*'
$filepath = "C:\Scripts\"
$date = "{0:yyy_MM_dd-HH_mm}" -f (get-date)
$file = $filepath + "Results_" + $date + ".htm"
New-Item $filepath -type directory -force -Verbose 

 $Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
<title>
 TSM Report
</title>
"@

ForEach ($server in $serverlist)
{

$Tsm = Get-Service -ComputerName $server| Where {$_.name -Like $SvcName}     


If ($Tsm.StartType -ne 'Automatic')
{

    Set-Service -InputObject $Tsm -StartupType Automatic
}
If ($Tsm.Status -ne 'Running')
{
    $output = "Starting the service."
    Start-Service -InputObject $Tsm
}

$Tsm2 = Get-Service -ComputerName $SysName | Where {$_.name -Like $SvcName}


} 
 $pre= "Here are the results for $date"

 $Tsm2 | Select-Object DisplayName, Status, StartupType | ConvertTo-HTML -Head $Header -PreContent $pre | Out-File $file

Invoke-Item $file

0 个答案:

没有答案