私は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
は誰が私にそれを修正する方法少なくともヒントを与えることはできますか? ありがとうございます!
'$ WMI = Get-WMIObject -Class Win32_DiskDrive'を' $ WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $ computername'に変更してみてください – ShanayL
'Get-WMIObject'にコンピュータ名を渡す必要があります。同様に: '$ WMI = Get-WMIObject -Class Win32_DiskDrive -ComputerName $ computername' –