Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Powershell:为什么某个字符串数组被格式化为“System.Int32”?_Arrays_Powershell - Fatal编程技术网

Arrays Powershell:为什么某个字符串数组被格式化为“System.Int32”?

Arrays Powershell:为什么某个字符串数组被格式化为“System.Int32”?,arrays,powershell,Arrays,Powershell,我试图将字符串成员添加到一个名为$htmlbodytest的数组中,在所有循环关闭后,我可以在脚本末尾通过电子邮件发送该数组 当我尝试用字符串成员填充数组而仅填充字符串成员时,为什么会收到以下错误消息: Cannot convert value "test server" to type "System.Int32". Error: "Input string was not in a correct format." 我在循环中的脚本中还有其他几个锯齿状数组,它们可以毫无问题地存储字符串。

我试图将字符串成员添加到一个名为$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 = @()
[……]

[……]


关闭ISE并重新打开此解决方案。我在不同的选项卡中使用相同的变量名,但总是填充字符串类型。我当然不会认为这是出于荣耀,而是为了避免在这个离奇的问题上浪费别人的时间

我很难找到一个问题,这对我来说并不重要。如果你改变声明,它会改变什么吗?[string[]$htmlbodytest=@。我觉得答案可能在缺少的代码中。是否还有其他地方尝试填充未显示的$htmlbodytest?我关闭了ISE,重新打开并更改了变量名,它现在可以工作了。我在一个单独的选项卡中声明了$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)