2017-10-28 3 views
0

私は2千台のコンピュータをチェックする必要があるので、ディスク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コマンドレットにコンピュータを合格していないので、あなたがオンになっているマシンから情報を取得することができるように見えます

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

$WMI = Get-WMIObject -Class Win32_DiskDrive 

を変更してみてください。

+1

ありがとうございます!最初に私は '$ WMI = Get-WMIObject -Class Win32_DiskDrive -Computername $ computer'を間違って試しました...あなたの説明は、もう少し書く機能を理解する助けになりました - ありがとうございました! – joeedit

関連する問題