2012-11-14 4 views
0

디스크 공간 결과를 되돌리려면 스크립트를 실행하여 서버 드라이브를 쿼리합니다. 이 질문에 대한 서버의 텍스트 파일 목록을 사용하여 스크립트가 실행됩니다. 나는 txt 파일에 하나의 서버 이름 만 가지고 궁극적으로 html 문서를 만듭니다.실행할 때 Foreach 루프가 누락되었습니다.

이 스크립트의 세 번째 예제를 사용할 때 서버의 올바른 드라이브 수가 반환되지 않기 때문에 문제가 발생합니다.

테스트 1.

Get-WmiObject 
    -ComputerName DB-server01 
    -Class Win32_LogicalDisk 
    -Filter "DriveType = 3" 

결과 :

DeviceID  : C: 
DriveType : 3 
ProviderName : 
FreeSpace : 28575797248 
Size   : 146056146944 
VolumeName : OS 

DeviceID  : V: 
DriveType : 3 
ProviderName : 
FreeSpace : 814725959680 
Size   : 898316103680 
VolumeName : SQLData 

DeviceID  : W: 
DriveType : 3 
ProviderName : 
FreeSpace : 293852868608 
Size   : 299436601344 
VolumeName : SQLLogs 

테스트 2.

$computers = Get-Content "C:\Powershell\servers.txt"; 
write-host $computers 
foreach($computer in $computers) 
{ 
    $disks = Get-WmiObject 
     -ComputerName $computer 
     -Class Win32_LogicalDisk 
     -Filter "DriveType = 3" 
    write-host $disks 
} 
그래서 이것을 테스트하기 위해 나는 다음과 같은했다 3,516,

결과

DB-SERVER01

DB-하여 Server01 \ 루트 \ cimv2를 \

: Win32_LogicalDisk.DeviceID = "C : \"DB-SERVER01 \ 루트 \ cimv2를 : Win32_LogicalDisk.DeviceID = "V" \ DB-하여 Server01 \ 루트 \ cimv2를 : Win32_LogicalDisk.DeviceID = "W"

테스트 3.

$i = 0; 
$percentWarning = 90; 
$percentCritcal = 25; 
$computers = Get-Content "C:\Powershell\servers.txt"; 
write-host $computers 

foreach($computer in $computers) 
{ 
    $disks = Get-WmiObject 
     -ComputerName $computer 
     -Class Win32_LogicalDisk 
     -Filter "DriveType = 3" 

    $computer = $computer.toupper() 

    foreach($disk in $disks) 
    {   
     $deviceID = $disk.DeviceID; 
     $volName = $disk.VolumeName; 
     [float]$size = $disk.Size; 
     [float]$freespace = $disk.FreeSpace; 
     $percentFree = [Math]::Round(($freespace/$size) * 100, 2); 
     $sizeGB = [Math]::Round($size/1073741824, 2); 
     $freeSpaceGB = [Math]::Round($freespace/1073741824, 2); 
     $usedSpaceGB = $sizeGB - $freeSpaceGB; 

     $color = $whiteColor; 

     if($percentFree -lt $percentWarning)  
     { 
      $color = $greenColor 
      if($percentFree -lt $percentCritcal) 
      { 
       $color = $redColor 
      }   

      if ($percentFree -eq "NaN") 
      { 
       $PercentFree = "N/A" 
       $Color = $whiteColor 
      } 

      Add-Content $diskReport $dataRow; 

      Write-Host -ForegroundColor Green 
       "$computer $deviceID percentage free space = $percentFree"; 

      $i++ 
     } 
    } 
} 

결과 :

DB-Server01 C: percentage free space = 19.56 

모양 시험 3를 통해 실행 만 C 드라이브를 다시 가져오고

W.

V &을 놓친 ??????? ; 이것은

$ percentWarning = 90 때문 - 왜 이런 일

+0

필자가 실제로 실현

if($percentFree -lt $percentWarning) { $color = $greenColor if($percentFree -lt $percentCritcal) { $color = $redColor } if ($percentFree -eq "NaN") { $PercentFree = "N/A" $Color = $whiteColor } } Add-Content $diskReport $dataRow; Write-Host -ForegroundColor Green "$computer $deviceID percentage free space = $percentFree"; $i++ } 

을} -이 때문 $ percentWarning = 90; $ percentCritcal = 25; 드라이브의 용량이 90 % 미만인 경우에만 출력을 성공으로 이끌어내는 경우가 있습니다. 일부 서버의 경우 여유 공간 값이 훨씬 높았으므로이 드라이브에 대한보고는 없었습니다. 필자는 그 값을 99 %로 수정하고 모든 드라이브를 다시 찾았습니다. – MoOriginal

답변

0

필자는 실제로 실현

드라이브의 용량이 90 % 미만인 경우에만 출력이 성공하는 것으로 나타났습니다. 일부 서버의 경우 여유 공간이 훨씬 많았으며이 드라이브는 확실히보고되었습니다. 필자는 99 %의 값을 편집 한 후 모든 드라이브를 다시 가져 왔습니다.

1

동일한 문제가 발생하여 디스크 공간이 충분한 디스크를 건너 뛰었 기 때문에 실제로 디스크가 표시되지 않는 것으로 나타났습니다. 모든 디스크를 표시하려면 스크립트를 조정해야합니다. 문제는 "}"가 문제없이 디스크에 올바르게 배치되지 않는다는 것입니다.백분율이 경고 수준 다음 낮은 경우 스크립트는 인쇄 된

당신은 마지막 비트를 변경할 수 있습니다 : 왜 이런 일

관련 문제