다음 스크립트를 사용하여 원격 서버에서 디스크 사용 통계를 수집합니다. 스크립트가 읽는. \ ServerIPs.txt 파일에서 IP가 아닌 호스트 이름을 표시하도록 출력을 얻으려고합니다. get-wmiobject Win32_LogicalDisk에서 "SystemName"검색을 시도했지만 표시 할 이름을 가져올 수 없습니다. 호스트 이름이 호스트 IP 주소가 아닌 보고서에 표시되도록하려면 무엇을 추가해야합니까?Powershell 디스크 사용 보고서
$erroractionpreference = "SilentlyContinue"
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Server Name"
$c.Cells.Item(1,2) = "Drive"
$c.Cells.Item(1,3) = "Total Size (GB)"
$c.Cells.Item(1,4) = "Free Space (GB)"
$c.Cells.Item(1,5) = "Free Space (%)"
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2
$colComputers = get-content ".\ServerIPs.txt"
foreach ($strComputer in $colComputers)
{
$colDisks = get-wmiobject Win32_LogicalDisk -computername $strComputer -Filter "DriveType = 3"
foreach ($objdisk in $colDisks)
{
$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()
$c.Cells.Item($intRow, 2) = $objDisk.DeviceID
$c.Cells.Item($intRow, 3) = "{0:N0}" -f ($objDisk.Size/1GB)
$c.Cells.Item($intRow, 4) = "{0:N0}" -f ($objDisk.FreeSpace/1GB)
$c.Cells.Item($intRow, 5) = "{0:P0}" -f ([double]$objDisk.FreeSpace/[double]$objDisk.Size)
$intRow = $intRow + 1
}
}
당신이를 얻기 위해 노력했다 무엇 name을 검색하기 위해서 어디에서나'$ objDisk.SystemName'이 보이지 않습니다'Get-WmiObject' 호출에'-Property DeviceID, SystemName, Size, FreeSpace'를 추가해보십시오. –
당신은'[System. NetDns] :: GetHostByAddress ("xxxx") 어떤 이유로 wmi가 작동하지 않는 경우 dns에서 호스트 이름을 얻으려고합니다. – Paul
둘 중 하나 또는 둘 다 대답 수 있습니다 – Matt