2014-03-13 1 views
0

2003 및 2008/r2 서버를 나열하는 Google 도메인의 서버 목록을 제공하려고합니다. 이 정보와 함께 나는 그들의 C 드라이브의 현재 상태 인 "여유 공간"& "디스크의 크기"를 알려 드리고자합니다. 아래의 스크립트는 정상적으로 실행되고 모든 올바른 운영 체제의 목록을 인쇄합니다. 그러나powershell - get-adcomputer 및 win32_logicaldisk 등록 정보

여유 공간과 크기는 모두 동일합니다. 첫 번째 서버의 상태를 알려주고 스크립트가 끝날 때까지 복제합니다. 스크립트 인쇄 예 :

serverName1 Windows server 2003 standard deviceid=c freespace=40gb size=12gb 
serverName2 Windows server 2008r2 standard deviceid=c freespace=40gb size=12gb 
.... 
serverName100 .....          freespace=40gb size=12gb 



Import-Module activedirectory 
$2008LogPath = "e:/2008servers.txt" 
$2003LogPath = "e:/2003servers.txt" 
$servers = get-adcomputer -Filter 'ObjectClass -eq "Computer"' -properties "OperatingSystem" 
foreach ($server in $servers) { 
    if($server.OperatingSystem -match "Windows Server 2008") { 
    Get-WmiObject win32_logicaldisk | Where-Object {$_.deviceid -match "C"} | 
    ft $server.name, $server.operatingsystem, deviceid, freespace, size -AutoSize }#Out-File -Append $2008LogPath } 

    elseif($server.operatingsystem -match "Windows Server 2003") { 
    Get-WmiObject win32_logicaldisk | Where-Object {$_.deviceid -match "C"} | 
    ft $server.name, $server.operatingsystem, deviceid, freespace, size -AutoSize }#Out-File -Append $2003LogPath } 
} 

답변

1

당신은 그 원격 컴퓨터에서 정보를 검색하려면 Get-WmiObject cmdlet의 -ComputerName 매개 변수를 사용해야합니다. -ComputerName 매개 변수를 지정하지 않으면 로컬 컴퓨터에서 WMI 데이터를 검색하고 있습니다. 솔루션과 뒤에 이유에 대한

foreach ($server in $servers) { 
    if($server.OperatingSystem -match "Windows Server 2008") { 
    Get-WmiObject -ComputerName $Server.Name -Class win32_logicaldisk | Where-Object {$_.deviceid -match "C"} | 
    ft $server.name, $server.operatingsystem, deviceid, freespace, size -AutoSize }#Out-File -Append $2008LogPath } 

    elseif($server.operatingsystem -match "Windows Server 2003") { 
    Get-WmiObject -ComputerName $Server.Name -Class win32_logicaldisk | Where-Object {$_.deviceid -match "C"} | 
    ft $server.name, $server.operatingsystem, deviceid, freespace, size -AutoSize }#Out-File -Append $2003LogPath } 
} 
+1

감사 :

은 다음과 같이 당신의 foreach 루프를 변경,이 문제를 해결합니다. 너무 오랫동안 나를 괴롭혔던 완전한 감각을 만든다! – Richard

+0

당신은 환영합니다, 친구! 다행 이네요. –