안녕하세요. 여기 내 스크립트가 있는데 remoteexitcode를 캡처하고 인수로 변수를 전달하려고하지만 작동하지 않습니다.내 스크립트에서 원격 세션을 사용할 수 없습니다.
은 내가 시도가 호출-명령에 -ArgumentList 사용 PARAM()를 사용하여 캡처 할 수있는 스크립트 블록 내 변수를 전달 할 수없는 생각하지만 나는 또한 오전
를 작동하지 않는 것 New-PSsession을 만드는 데 또 다른 문제점이 있습니다. 값이 저장되지 않는 것 같아요. 이유는 알지 못합니다.
[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
}
: 종료 코드는 다음과 같은 에러가 발생 1.
경우 내가 실패로 표시 할 수 있도록 나 원격 세션을 사용하기위한 주요 목표는 패스를 종료 코드의 값입니다