一連の手順を実行して HTML ファイルを作成しようとしています。以下はコードです:
$bkpstat = @()
$a = Get-Date
$b = $a.AddDays(-1)
$b = $b.ToShortDateString();
$StartTime = "10:00:00 PM"
$EndTime = "11:00:00 PM"
$before = $b + " " + $StartTime
$after = $b + " " + $EndTime
$before = [datetime]$before
$after = [datetime]$after
$sms_svc = "SMS Agent Host","SMS_EXECUTIVE","SMS_SITE_COMPONENT_MANAGER","SMS_SITE_VSS_WRITER","SMS_REPORTING_POINT","SMS_SERVER_LOCATOR_POINT"
$smsdb_svc = "SMS Agent Host","SMS_SITE_SQL_BACKUP_WDSMS01"
$style = "<style>$(get-content C:\Temp\Rajiv\style.css)</style>"
$bkpsys = New-Object PSObject
$bkpsys | Add-Member -type NoteProperty -name SiteCode -value 000
$bkpstat += $bkpsys
if(Test-Connection WDSMS01 -Count 3 -BufferSize 3 -Quiet)
{
Write-Host "SMS01 is available. Checking service status"
$cmsvc_000 = Get-Service $sms_svc -ComputerName SMS01 | Convertto-HTML -Property Name, Status -PreContent "<h2>Service Status for SMS01 </h2>" | Out-String
Write-Host "Checking Site Server backup for 000"
$smsbkp_000 = Get-EventLog -ComputerName SMS01 -LogName Application -After $after -Before $before -Source "SMS Server" | ?{$_.EventID -eq 6833} | Select MachineName, Message
if ($smsbkp_000)
{
$bkpsys | Add-Member -type NoteProperty -Name SiteServer -Value "Success"
}
else
{
$bkpsys | Add-Member -type NoteProperty -Name SiteServer -Value "Failed"
}
}
else
{
Write-Host "Server SMS01 is not reachable"
$bkpsys | Add-Member -type NoteProperty -name SiteServer -value "Not Reachable"
}
if(Test-Connection SCCMSQL01 -Count 3 -BufferSize 3 -Quiet)
{
Write-Host "SCCMSQL01 is available. Checking service status"
$cmdbsvc_000 = Get-Service $smsdb_svc -ComputerName SCCMSQL01 | Convertto-HTML -Property Name, Status -PreContent "<h2>Service Status for SCCMSQL01 </h2>" | Out-String
Write-Host "Checking Database backup for SMS_000"
$sqlbkp_000 = Get-EventLog -ComputerName SCCMSQL01 -LogName Application -After $after -Before $before -Source "MSSQLSERVER" | ?{$_.EventID -eq 18264} | Select MachineName, Message
if ($sqlbkp_000)
{
$bkpsys | Add-Member -type NoteProperty -name Database -value "Success"
}
else
{
$bkpsys | Add-Member -type NoteProperty -Name Database -Value "Failed"
}
}
else
{
Write-Host "Server SCCMSQL01 is not reachable"
$bkpsys | Add-Member -type NoteProperty -name Database -value "Not Reachable"
}
$bkpstat
$params = @{'Head'="<title>Report for ConfigMgr Site 000</title>$style";
'PreContent'="<h1>Daily Check</h1>";
'PostContent'=$cmsvc_000, $cmdbsvc_000, $bkpstat}
Convertto-HTML @params | Out-File C:\Temp\Rajiv\Site_000.html
私が得るエラーメッセージは次のとおりです。
ConvertTo-Html : 'System.Object[]' を、パラメーター 'PostContent' で必要なタイプ 'System.String' に変換できません。指定されたメソッドはサポートされていません。C:\temp\rajiv\DailyCheck_000.ps1:88 文字:16 + Convertto-HTML <<<< @params | Out-File C:\Temp\Rajiv\Site_000.html + CategoryInfo: InvalidArgument: (:) [ConvertTo-Html]、ParameterBindingException + FullyQualifiedErrorId: CannotConvertArgument,Microsoft.PowerShell.Commands.ConvertToHtmlCommand
$bkp の Convertto-HTML の有無にかかわらず、Out-String を使用してみましたが、無駄でした。誰か助けてください。
ありがとう!