调用命令失败

问题描述

我一直在尝试将 Invoke-command 应用到这个脚本中,但没有成功任何想法?

看起来你的帖子主要是代码;请添加更多详细信息。 这是我的代码

$ServerListFile = "C:\Group 25.txt"
$OutputFile = "C:\Group 258.HTM"
$MAX_LOAD_THRESHOLD = 50

$Outputreport = "<HTML><TITLE>  Server Health Report </TITLE> 
<BODY background-color:peachpuff> 
<font color =""#99000"" face=""Microsoft Tai le""> 
<H2> Exchange Server Health Report </H2></font> 
<Table border=1 cellpadding=0 cellspacing=0> 
<TR bgcolor=gray align=center> 
 <TD><B>Server Name</B></TD> 
 <TD><B>Avrg.cpu utilization</B></TD> 
 <TD><B>Memory utilization</B></TD> 
 <TD><B>C Drive utilization</B></TD></TR>" 

$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue  

$Result = Invoke-Command -ComputerName USCDC01TWMSP001  { 
 try {
   $computername = $_

   $AVGProc = Get-CimInstance -computername $computername win32_processor |  
   Measure-Object -property LoadPercentage -Average | Select-Object Average 
   $OS = Get-CimInstance -computername $computername win32_operatingsystem | 
   Select-Object @{Name = "MemoryUsage"; Expression = { [System.Math]::Round(((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory) * 100) / $_.TotalVisibleMemorySize),2) } } 
   $vol = Get-CimInstance -ComputerName $computername win32_Volume -Filter "DriveLetter = 'C:'" | 
   Select-object @{Name = "C PercentFree"; Expression = { [System.Math]::Round( (($_.FreeSpace / $_.Capacity) * 100),2) } }  

   #Return Good Data Object
   $result = [PSCustomObject] @{  
     ServerName = "$computername" 
     cpuLoad    = $($AVGProc.Average) 
     Memload    = $($OS.MemoryUsage)
     CDrive     = $($vol.'C PercentFree') 
     HasError   = $false
   }
 }
 catch {
   #Return Bad Data Object
   $result = [PSCustomObject] @{  
     ServerName = "$computername" 
     cpuLoad    = "Error" 
     Memload    = "Error" 
     CDrive     = "Error" 
     HasError   = $true
   }
 }

 return $result
} -ThrottleLimit 5
                         
Foreach ($Entry in $Result) {  
 if (($Entry.cpuLoad -gt $MAX_LOAD_THRESHOLD) -or ($Entry.memload -gt $MAX_LOAD_THRESHOLD)) {  
   $Outputreport += "<TR bgcolor=red>"; $I++  
 }  
 else { 
   $Outputreport += "<TR>"  
 } 
 $Outputreport += "<TD>$($Entry.Servername)</TD><TD align=center>$($Entry.cpuLoad)%</TD><TD align=center>$($Entry.Memload)%</TD><TD align=center>$($Entry.Cdrive)%</TD></TR>"  
} 
 
$Outputreport += "</Table></BODY></HTML>"  

$Outputreport | out-file $OutputFile  

function Send-Report() {
 Invoke-Expression $OutputFile
 ##Send email functionality from below line,use it if you want    
 #$smtpServer = "webmail.bcdtravel.com" 
 #$smtpFrom = "[email protected]" 
 #$smtpTo = "[email protected]" 
 ##$messageSubject = "Exchange Server Health report" 
 #$message = New-Object System.Net.Mail.MailMessage $smtpfrom,$smtpto 
 #$message.Subject = $messageSubject 
 ##$message.IsBodyHTML = $true 
 #$message.Body = "<head><pre>$style</pre></head>" 
 ##$message.Body += Get-Content $OutputFile
 $smtp = New-Object Net.Mail.SmtpClient($smtpServer) 

 if ($I -ge 1) { 
   $smtp.Send($message)
 }
}

Remove-Variable * -ErrorAction SilentlyContinue

谢谢 看来您的帖子主要是代码;请添加更多详细信息。

看起来你的帖子主要是代码;请添加更多详细信息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)