디스크 공간 결과를 되돌리려면 스크립트를 실행하여 서버 드라이브를 쿼리합니다. 이 질문에 대한 서버의 텍스트 파일 목록을 사용하여 스크립트가 실행됩니다. 나는 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 때문 - 왜 이런 일
필자가 실제로 실현
을} -이 때문 $ percentWarning = 90; $ percentCritcal = 25; 드라이브의 용량이 90 % 미만인 경우에만 출력을 성공으로 이끌어내는 경우가 있습니다. 일부 서버의 경우 여유 공간 값이 훨씬 높았으므로이 드라이브에 대한보고는 없었습니다. 필자는 그 값을 99 %로 수정하고 모든 드라이브를 다시 찾았습니다. – MoOriginal