You should remove the password from the .txt file that you posted.
but it is giving me some error.
It would be helpful if you posted the error and what statement it occurred on.
It appears that you are processing hostedsql3 twice.
If $result is always processed the same way, then maybe something like this.
foreach($Servers in $Computers) {
$Query = 'EXEC da..sp_DBStatus'
if($Servers -eq "hostedsql3") {
$Result = Invoke-Sqlcmd ($Query) -ServerInstance $Servers -Username "vishwakarmac" -Password "********"
} else {
$Result = Invoke-Sqlcmd ($Query) -ServerInstance $Servers
}
# Now process the results
foreach ($Item in $Result) {
$ServerNames = $Item.ServerName
$DBName = $Item.DBName
$state_desc = $Item.state_desc
$recovery_model_desc = $Item.recovery_model_desc
$log_reuse_wait_desc = $Item.log_reuse_wait_desc
$HTML += "<TR>
<TD>$($ServerNames)</TD>
<TD>$($DBName)</TD>
<TD>$($state_desc)</TD>
<TD>$($recovery_model_desc)</TD>
<TD>$($log_reuse_wait_desc)</TD>
</TR>"
}
}