2013-07-23 2 views
0

Привет, вот мой скрипт, и я хочу захватить файл remoteexit и передать переменные в качестве аргументов, но он не работает.Невозможно использовать удаленный сеанс в моем сценарии

Я не в состоянии передать свои переменные в блок скрипта, который пытается использовать -ArgumentList в Invoke-Command и захватить его с помощью параметров(), но это не похоже на работу

Я также имея еще одну проблему с созданием новой PSsession, ценность, кажется, не сохраняется, и я не понимаю почему. Основная цель для меня используйте удаленный сеанс является перевал значения выходного кода, так что я могу показать его как провал, если код завершения 1.

я получаю следующее сообщение об ошибке:

[10:23:52][Step 1/2] Invoke-Command : Parameter set cannot be resolved using the specified named par [10:23:52][Step 1/2] ameters. [10:23:52][Step 1/2] At D:\TeamCityAgent2\work\a4e87a75117c6a1b\CheckLogsize.ps1:95 char:15 [10:23:52][Step 1/2] + Invoke-Command <<<< -ScriptBlock {$runscript} -ComputerName $hostName -Sessi [10:23:52][Step 1/2] on $remotesession [10:23:52][Step 1/2] + CategoryInfo : InvalidArgument: (:) [Invoke-Command], Parameter [10:23:52][Step 1/2] BindingException [10:23:52][Step 1/2] + FullyQualifiedErrorId : >AmbiguousParameterSet,Microsoft.PowerShell.Comma [10:23:52][Step 1/2] nds.InvokeCommandCommand

param(
[String]$H = "null" 
) 

[String]$hostName = [String]$H 
Get-Date 

[int]$logsize1 = 0 
[int]$logsize2 = 0 
[int]$logsizediff = 0 
[array]$Emaillist = "[email protected] 
[String]$EmailSubj = "Log size warning" 
[String]$Emailfrom = "[email protected]" 
[String]$EmailBody = "Stopping Apache and TC service due excessive logging" 
[String]$logfolder = "D:\hmonline\servers\tcserver\hmonline-instance\logs\hybris.log" 

$runscript = { 

param([String]$rechostName, [int]$reclogsize1, [int]$reclogsize2, [int]$reclogsizediff, [String]$reclogfolder) 

Function checklogsize 
{ 

If(($reclogsize2 -gt 40000000) -or $logsizediff -gt 20000000) 
{ 
    Send-MailMessage -From "[email protected]" -Subject "$recEmailSubj on $rechostName" -To $recEmaillist -Body ` 
    " 
    <head> 
    </head> 
    <body>  
     <h2> Log Size Exceeded the limit or there was a Spike in the log </h2> 
     <table border=2 class=logdetails align=center> 
      <tr> 
       <th> Log Size </th> <td> $reclogsize2 </td> 
      </tr> 
      <tr> 
       <th> Log growth in last 20 mins </th> <td> $reclogsizediff </td> 
      </tr> 
      <tr> 
       <th> Log Location </th> <td> $reclogfolder </td> 
      </tr> 
     </table> 
    </body> 
" -BodyAsHtml -Priority Normal -SmtpServer smtp.hm.com 
    Write-Error -Message "Log sizes have exceeded the limit or growing too fast" -Category LimitsExceeded 
    Exit 1 
} 
Else 
{ 
    Get-Date 
    Write-Host -NoNewline "Log sizes are stable" 
    Exit 0 
} 
} 

$reclogsize1=(Get-Item $reclogfolder).length 
Start-Sleep 300 
$reclogsize2=(Get-Item $reclogfolder).length 
$reclogsizediff = $reclogsize2 - $reclogsize1 
Write-Host $reclogsize1 
Write-Host $reclogsize2 
Write-Host $reclogsizediff 

checklogsize 
} 



If($hostName -eq "secc1794") 
{ 
$remotesession = New-PSSession -ComputerName $hostName 

Invoke-Command -ScriptBlock {$runscript} -ComputerName $hostName -Session $remotesession -ArgumentList $hostName, $logsize1, $logsize2, $logsizediff, $logfolder 

$remotelastexitcode = invoke-command -ScriptBlock {$lastexitcode} -Session $remotesession 
Invoke-Command -ComputerName $hostName -ScriptBlock {$runscript} 
Write-Host -NoNewline "Log size1 is:" 
Write-Host $logsize1 
$remotelastexitcode 
} 

Else 
{ 
Write-Error -Message "Unknow Host stopping process" -Category ObjectNotFound 
Exit 0 
} 

ответ

0

Вы должны передать ваши аргументы в brakets, как это:

Invoke-Command -ScriptBlock {$runscript} -ComputerName $hostName -Session $remotesession -ArgumentList ($hostName, $logsize1, $logsize2, $logsizediff, $logfolder) 

в противном случае PowerShell не распознает его как массив

Смежные вопросы