2017-10-28 5 views
0

2,000 대의 컴퓨터를 검사해야하기 때문에 디스크 SMART prefail 상태를 확인하는 스크립트의 속도를 높이려고합니다. 그러나 스크립트는 여전히 동일한 디스크에 대한 상태를 기록하고 있습니다 - "hostname1"및 "hostname2"컴퓨터는 서로 다른 디스크를 가지고 있습니다.워크 플로우에 대한 기능 만들기 - Powershell

function disk-status(){ 
     param(
      [Parameter(Mandatory=$true)][string]$computername 
      ) 
       $WMI = Get-WMIObject -Class Win32_DiskDrive 
       ForEach ($Drive in $WMI){ 
       $disk = $Drive.Caption 
       $status = $Drive.Status 
       #condition will be changed to "-notmatch" 
       if ($status -match "OK"){ 
         #I'm using write-output to see if the script works during testing 
         Write-output $computername $disk $status 
         } 
       } 
} 



workflow Get-disk-status { 
    param(
    [string[]]$computers 
) 
    foreach -parallel ($computer in $computers) {   
     disk-status -computername $computer 

    } 
} 

#in the final version I'm going to use get-adcomputer 
$computers = "hostname1", "hostname2" 

Get-disk-status $computers 

출력 내가 얻을 :

hostname1 
ST500LM0 21-1KJ152 SCSI Disk Device 
OK 
hostname2 
ST500LM0 21-1KJ152 SCSI Disk Device 
OK 

는 아무도 나에게 그것을 해결하는 방법을 적어도 힌트를 줄 수 있습니까? 미리 감사드립니다.

+1

'$ WMI = Get-WMIObject -Class Win32_DiskDrive'를'$ WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $ computername'으로 변경해보십시오. – ShanayL

+1

컴퓨터 이름을'Get-WMIObject'에 전달해야합니다. 이렇게 :'$ WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $ computername' –

답변

2

보십시오 당신이 Get-WMIObject cmdlet으로 컴퓨터를 통과하지 않았기 때문에 당신이있는 시스템에서 정보를 검색 할 수있다처럼 보이는

$WMI = Get-WMIObject -Class Win32_DiskDrive 

$WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $computername 

에 변경.

+1

모두 감사합니다! 처음에는'$ WMI = Get-WMIObject -Class Win32_DiskDrive -Computername $ computer'을 시도했습니다 ... 당신의 설명은 글쓰기 기능을 조금 더 이해할 수있게 도와 줬습니다 - 다시 한 번 감사드립니다! – joeedit