小编Jas*_*son的帖子

方法调用失败 op_addition

在这个脚本中,我从我的 SQL 服务器中提取信息。我创建了 psobject,然后我尝试将每个对象 += 放入 $results 表中,以便我可以获得完整的最终报告。出于某种原因,如果我一直运行脚本,它会给我错误

方法调用失败,因为 [system.management.managementobject] 不包含名为“op_Addition”的方法

但是,如果我逐行运行脚本,则不会出现错误。

$Results = @()
$servers = get-content .\computers.txt
ForEach ($server in $servers) {
   # Ping the machine to see if it's on the network
   $results = Get-WMIObject -query "select StatusCode from 
Win32_PingStatus where Address = '$server'" 
   $responds = $false   
   ForEach ($result in $results) {
      # If the machine responds break out of the result loop and indicate success
      if ($result.statuscode -eq 0) {
         $responds = $true
         break
      }
   } …
Run Code Online (Sandbox Code Playgroud)

powershell psobject

3
推荐指数
1
解决办法
7306
查看次数

标签 统计

powershell ×1

psobject ×1