Powershell错误:HRESULT异常:0x800A03EC [英] Powershell Error: Exception from HRESULT: 0x800A03EC

查看:74
本文介绍了Powershell错误:HRESULT异常:0x800A03EC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何帮助都会很棒.遇到此错误,我无法弄清楚为什么它无法写入第4行.我尝试了不同的格式,但仍然继续抛出该错误.我已经尝试在XLS和CSV.没有运气,再次提供任何帮助将非常感谢!

Any help for this would be great. running into this error and i am unable to figure out why its failing to write to row 4. I have tried different formats and still continues to throw the error. i have tried this in xls and csv. no luck, again any help would be great thank you!

$path = ".\results.csv"

$objExcel = new-object -comobject excel.application 

if (Test-Path $path) { 
    $objWorkbook = $objExcel.WorkBooks.Open($path) 
    $objWorksheet = $objWorkbook.Worksheets.Item(1) 
} else { 
    $objWorkbook = $objExcel.Workbooks.Add() 
    $objWorksheet = $objWorkbook.Worksheets.Item(1)
}

$objExcel.Visible = $True

#########Add Header#########

$objWorksheet.Cells.Item(1, 1) = "MachineIP"
$objWorksheet.Cells.Item(1, 2) = "Result"
$objWorksheet.Cells.Item(1, 3) = "HostName"
$objWorksheet.Cells.Item(1, 4) = "ServiceTag"

$ipadd = Read-Host "Please enter the IP address ex. 10.0.0. "
75..190 | ForEach-Object {$ipadd + "$_"} | Out-File -FilePath .\machinelist.txt
Start-Sleep -s 3

$machines = gc .\machinelist.txt
$count = $machines.count

$row=2

$machines | foreach-object{
$ping=$null
$hname =$null
$machine = $_
$ping = Test-Connection $machine -Quiet -Count 1 -ea silentlycontinue
if($ping){
    try{
    $hname = [System.Net.Dns]::GetHostByAddress($machine).HostName
    }catch{}
    try{
    $stag = Get-WmiObject -ComputerName $machine Win32_BIOS | Select-Object SerialNumber
    }catch{}
    $objWorksheet.Cells.Item($row,1) = $machine
    $objWorksheet.Cells.Item($row,2) = "UP"
    $objWorksheet.Cells.Item($row,3) = $hname  
    $objWorksheet.Cells.Item($row,4) = $stag              
    $row++

} else {

}
}

Remove-Item -Path .\machinelist.txt -Force

推荐答案

运行代码时,我看到了两个不断弹出的问题.

When I ran your code, I saw two issues that kept popping up.

  1. RPC服务器不可用(对于无法解析的IP地址)
  2. 无法为单元格分配值.

对于1,我只是添加了 -ErrorAction SilentlyContinue ,对于2,我对$ stag的值添加了引号.查看脚本

For 1, I simply added -ErrorAction SilentlyContinue and for 2, i added quotes around the value for $stag. See script

if($ping){
    try{
    $hname = [System.Net.Dns]::GetHostByAddress($machine).HostName
    }catch{}
    try{
        $stag = Get-WmiObject -ComputerName $machine Win32_BIOS -ErrorAction SilentlyContinue | Select-Object SerialNumber
        $objWorksheet.Cells.Item($row,1) = "$machine"
        $objWorksheet.Cells.Item($row,2) = "UP"
        $objWorksheet.Cells.Item($row,3) = "$hname"
        $objWorksheet.Cells.Item($row,4) = "$stag"
    }
    catch{
        $objWorksheet.Cells.Item($row,1) = "$machine"
        $objWorksheet.Cells.Item($row,2) = "DOWN"
        $objWorksheet.Cells.Item($row,3) = "$hname"  
        $objWorksheet.Cells.Item($row,4) = "$stag"
    }
    $row++
}

如果该帖子帮助您找到了解决方案,请将该帖子标记为已回答.

这篇关于Powershell错误:HRESULT异常:0x800A03EC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆