我正在尝试将字符串成员添加到名为$htmlbodytest
的数组中,然后我可以在脚本的末尾发送电子邮件(在所有循环关闭之后)。
当我尝试使用字符串成员(并且只有字符串成员)填充数组时,为什么会出现以下错误消息?:
Cannot convert value "test server" to type "System.Int32". Error: "Input string was not in a correct format."
更多细节:
# before loops begin, array is declared as:
$htmlbodytest = @()
[...]
foreach ($server_name in $server_names) {
Start-Job -Scriptblock {
#If server fails a ping test, skip it and add to array to email
if(!(Test-Connection -ComputerName $using:server_name -Quiet)) {
$htmlbodytest += "$using:server_name"
continue
} else {
[...]
} # after work of loop is finished, send email
$smtpServer = "10.10.10.10"
$smtpFrom = "from@co.com"
$smtpTo = "to@co.com"
$messageSubject = "Servers that didn't record uptime this month due to no ping"
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$message.Body = $htmlbodytest | ForEach-Object {Add-Member -InputObject $_ -Type NoteProperty -Name Servers -Value $_; $_} | ConvertTo-Html -Head $a -Property Server
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
答案 0 :(得分:0)
关闭ISE并重新打开此解决了这个问题。我在不同的选项卡中使用了相同的变量名,但总是填充字符串类型。我当然不会将此标记为荣耀中的回答,而是为了防止浪费他人。在这个片状问题上的时间。