2014-05-13 3 views
-3

내 스크립트에서 두 변수를 비교하고 싶습니다. 예 :if 문 내에서 값을 변경하십시오.

if ($1 -eq $2) {$checkbox.checked=$true} 

내 문제는 checkbox.checked의 값이 변경되지 않는 것입니다. 왜? "그 다음"에 지휘관을 수행하는 것은 불가능합니까?

영어로 유감입니다. 정말 도움이되기를 바랍니다.

요한.

+3

당신은 더 많은 코드를 제공 할 수 있습니까? 우리는이 한 줄을 바탕으로 당신을 정말로 도울 수 없습니다. – HAL9256

+0

코드가 작동해야합니다. 오류는 코드의 다른 위치에 있어야합니다. 오류를 찾기 위해 스크립트의 나머지 부분을 확인해야합니다. –

+0

코드를 PowerShell ISE에서 실행하십시오. 그 줄에 중단 점을 놓고 $ 1과 $ 2에 무엇이 있는지보십시오. 그것들이 무엇인지를보기 위해서'write-host $ 1 $ 2'와 같은 것을하거나합니다. –

답변

0
} 
#start 
#we check ram freee 
$machine = Get-WmiObject win32_computersystem 
$ram = [int64]$machine.TotalPhysicalMemory/1MB 
$ram2 = Get-WmiObject Win32_OperatingSystem 
$ramfree = [int64]$ram2.FreePhysicalMemory/1024 
$txtbox_ram.Text = [math]::round($ramfree,1) 
$rampercent = $ramfree/$ram*100 
[int]$intram = $rampercent.value 
$txtbox_ramtotale.Text = [math]::round($rampercent) 

#we check space disk used in C: 
$space = Get-WmiObject Win32_LogicalDisk 
$spacec = $space |ForEach-Object {$_.size/1MB} 
$spacefreec = $space | ForEach-Object {$_.freespace/1MB} 
$txtbox_disk.text =[math]::round($spacec[0],1) 

$spacediskpercent = ($spacefreec[0])/($spacec[0])*100 
[int]$intdisk = $spacediskpercent.value 

$txtbox_diskpercent.Text = [math]::round($spacediskpercent) 

#test if space disk use < 90 then checkbox = true 
$seuil = [int]10 
if ($intram.value -le $seuil.value) 
{$chkbox.Checked = $true} 

#test if space disk use < 90 then checkbox = true 
[int]$seuil = 90 
if ($intdisk -gt $seuil) 
{$chkbox.Checked = $true} 

} 

명확하지 않은 경우 2 정수를 비교하고 맞으면 확인란을 선택하십시오. 도움에 감사드립니다.

0

문제는 $variable.value으로 작동하는 PowerShell 변수에서 값을 가져 오는 중입니다.

그래서이 실행 :
[int]$intram = $rampercent.value 

이 작동하지 않습니다. 이것은 또한 당신이 있다는 것을 의미

[int]$intram = $rampercent 

지금 $intram 정확한 수를 포함 $intram 그냥 ".value"없이이 같은 변수를 사용하는 대신

0의 값을 갖게됩니다 이 설정을 변경 :

[int]$intdisk = $spacediskpercent.value 

을이 사람 :

[int]$intdisk = $spacediskpercent 

그리고에서 체크 박스를 설정 선언문 경우 :

if ($intram.value -le $seuil.value) 

하려면 :

if ($intram -le $seuil) 
관련 문제